jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From casta...@apache.org
Subject svn commit: r1238936 - in /incubator/jena/Jena2/ARQ/trunk/src: main/java/org/openjena/atlas/json/io/JSWriter.java test/java/org/openjena/riot/out/TestOutputRDFJSON.java
Date Wed, 01 Feb 2012 04:38:32 GMT
Author: castagna
Date: Wed Feb  1 04:38:32 2012
New Revision: 1238936

URL: http://svn.apache.org/viewvc?rev=1238936&view=rev
Log:
JENA-206

Patch applied, thank you Rob.

Modified:
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/json/io/JSWriter.java
    incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestOutputRDFJSON.java

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/json/io/JSWriter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/json/io/JSWriter.java?rev=1238936&r1=1238935&r2=1238936&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/json/io/JSWriter.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/json/io/JSWriter.java
Wed Feb  1 04:38:32 2012
@@ -277,7 +277,7 @@ public class JSWriter
     private void setNotFirst()      { stack.peek().setValue(false) ; }
     
     // Can only write a value in some context.
-    private void value(String x) { out.print("\"") ; out.print(x) ; out.print("\"") ; }
+    private void value(String x) { out.print(outputQuotedString(x)); }
     
     private void value(boolean b) { out.print(Boolean.toString(b)) ; }
     

Modified: incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestOutputRDFJSON.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestOutputRDFJSON.java?rev=1238936&r1=1238935&r2=1238936&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestOutputRDFJSON.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestOutputRDFJSON.java
Wed Feb  1 04:38:32 2012
@@ -18,23 +18,24 @@
 
 package org.openjena.riot.out;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream ;
+import java.io.ByteArrayOutputStream ;
 
-import org.junit.Test;
-import org.openjena.atlas.json.JSON;
-import org.openjena.atlas.json.JsonObject;
-import org.openjena.atlas.junit.BaseTest;
-import org.openjena.atlas.lib.Sink;
+import org.junit.Test ;
+import org.openjena.atlas.json.JSON ;
+import org.openjena.atlas.json.JsonObject ;
+import org.openjena.atlas.junit.BaseTest ;
+import org.openjena.atlas.lib.Sink ;
 import org.openjena.atlas.lib.StrUtils ;
-import org.openjena.riot.RiotReader;
-import org.openjena.riot.lang.LangRIOT;
-import org.openjena.riot.lang.SinkTriplesToGraph;
-
-import com.hp.hpl.jena.graph.Graph;
-import com.hp.hpl.jena.graph.Triple;
-import com.hp.hpl.jena.sparql.graph.GraphFactory;
-import com.hp.hpl.jena.sparql.sse.SSE;
+import org.openjena.riot.RiotReader ;
+import org.openjena.riot.lang.LangRIOT ;
+import org.openjena.riot.lang.SinkTriplesToGraph ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.graph.GraphFactory ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
 
 public class TestOutputRDFJSON extends BaseTest
 {
@@ -116,6 +117,7 @@ public class TestOutputRDFJSON extends B
               "(<http://example.org/abc> <p> _:s)" ,
               "))") ;
     }
+    
     @Test public void rdfjson_literals()
     {
         // Literals, various
@@ -128,16 +130,32 @@ public class TestOutputRDFJSON extends B
              "(<s> <p> '1.05'^^xsd:decimal)",
             "))") ;
     }    
+    
+    @Test public void rdfjson_escapes()
+    {
+    	Graph g = GraphFactory.createGraphMem();
+    	Node s = Node.createAnon();
+    	Node p = Node.createURI("http://predicate");
+    	g.add(new Triple(s, p, Node.createLiteral("quote \" character")));
+    	g.add(new Triple(s, p, Node.createLiteral("new \n\r lines")));
+    	g.add(new Triple(s, p, Node.createLiteral("tab \t character")));
+    	test(g);
+    }
 
     private void test (String... strings) 
     {
         String str = StrUtils.strjoinNL(strings) ;
         Graph g = SSE.parseGraph(str) ;
+        test(g);
+    }
+    
+    private void test (Graph g)
+    {
         ByteArrayOutputStream bout = serializeAsJSON(g) ;
         parseAsJSON(bout) ; // make sure valid JSON
         Graph g2 = parseAsRDFJSON(bout) ; 
 
-        assertTrue(g.isIsomorphicWith(g2)) ;    	
+        assertTrue(g.isIsomorphicWith(g2)) ;  
     }
 
     private ByteArrayOutputStream serializeAsJSON (Graph graph) 



Mime
View raw message