changeset 353:883351632db8

~ minimally escape IRI components
author Eric Prud'hommeaux <eric@w3.org>
date Wed, 16 Feb 2011 20:15:27 -0500
parents f3cf25dbba52
children ec859fb55933
files directmapping-webapp/src/main/scala/Servlet.scala directmapping/src/main/scala/DirectMapping.scala
diffstat 2 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/directmapping-webapp/src/main/scala/Servlet.scala	Wed Feb 16 17:56:29 2011 -0500
+++ b/directmapping-webapp/src/main/scala/Servlet.scala	Wed Feb 16 20:15:27 2011 -0500
@@ -232,10 +232,10 @@
   }
 
   override def doPost(request:HttpServletRequest, response:HttpServletResponse) = {
-    val urlencode = request.getParameter("urlencode") == "on"
+    val minEncode = request.getParameter("minEncode") == "on"
     request.getParameter("sql") match {
       case null | "" => processIndex(request, response)
-      case sql       => processSQL(request, response, sql, urlencode)
+      case sql       => processSQL(request, response, sql, minEncode)
     }
   }
 
@@ -270,7 +270,7 @@
             { List("1table0rows", "1table1row", "1table2columns1row", "1table3columns1row", "2duplicates0nulls", "varchar_varchar_1row", "1table1compositeprimarykey3columns1row", "1table1primarykey1column1row", "2tables1primarykey1foreingkey") map renderVar }
 	  </div>
 	  </div>
-	  <p><input name="urlencode" checked="checked" type="checkbox" />Urlencode IRI components (vs. just encode [%,#=/>])</p>
+	  <p><input name="minEncode" checked="checked" type="checkbox" />Minimally encode IRI components (just encode [%&lt;+ /\.#&gt;])</p>
 	  <p><input value="clear" type="button" onclick="document.getElementById('sql').value = '';" /></p>
 	  <p><input id="submit" value="submit SQL" type="submit" /></p>
         </form>
@@ -283,12 +283,12 @@
       </body>
     </html>
 
-  def processSQL(request:HttpServletRequest, response:HttpServletResponse, sql:String, urlencode:Boolean) {
+  def processSQL(request:HttpServletRequest, response:HttpServletResponse, sql:String, minEncode:Boolean) {
 
     val result:String =
       try {
         val db = SQLParser.toDB(sql)
-        DirectMapping.Urlencode = urlencode
+        DirectMapping.MinEncode = minEncode
         val computedGraph:Graph = directDB(db)
         jenaSerializer(computedGraph)
       } catch {
--- a/directmapping/src/main/scala/DirectMapping.scala	Wed Feb 16 17:56:29 2011 -0500
+++ b/directmapping/src/main/scala/DirectMapping.scala	Wed Feb 16 20:15:27 2011 -0500
@@ -61,7 +61,7 @@
      */
     var HierarchyDetection = true
 
-    var Urlencode = true
+    var MinEncode = true
 
     /**
      * The mapping functions implementing
@@ -198,11 +198,11 @@
   
     def nodemap (rn:RelName, as:List[AttrName], ls:List[LexicalValue]) : IRI = {
       val pairs:List[String] = as.zip(ls) map { case (attrName, lexicalValue) => UE(attrName) + "." + UE(lexicalValue.s) }
-      IRI(UE(rn) + "/" + pairs.mkString("_") + "#_")
+      IRI(UE(rn) + "/" + pairs.mkString(",") + "#_")
     }
   
     def predicatemap (rn:RelName, as:List[AttrName]) : IRI = {
-      val encoded = as.map {c => UE(c)} mkString("_")
+      val encoded = as.map {c => UE(c)} mkString(",")
       IRI(UE(rn) + "#" + encoded)
     }
 
@@ -226,19 +226,19 @@
       }
   
     def UE (s:String) : String = {
-      if (Urlencode) {
+      if (MinEncode) {
+	s.replaceAll("%", "%25")
+	 .replaceAll("<", "%3C")
+	 .replaceAll("\\+", "%2B")
+	 .replaceAll(" ", "+")
+	 .replaceAll("/", "%2F")
+	 .replaceAll("\\.", "%2C")
+	 .replaceAll("#", "%23")
+	 // .replaceAll("=", "%3D")
+	 .replaceAll(">", "%3E")
+      } else {
 	val r = URLEncoder.encode(s, "UTF-8")
 	r
-      } else {
-	s.replaceAll("%", "%25")
-	 .replaceAll("\\+", "%2B")
-	 .replaceAll(" ", "+")
-	 .replaceAll(",", "%2C")
-	 .replaceAll("#", "%23")
-	 .replaceAll("=", "%3D")
-	 .replaceAll("/", "%2F")
-	 .replaceAll("<", "%3C")
-	 .replaceAll(">", "%3E")
       }
     }
 
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.