lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1103985 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ solr/ solr/CHANGES.txt solr/src/java/org/apache/solr/response/JSONResponseWriter.java solr/src/test/org/apache/solr/request/JSONWriterTest.java
Date Tue, 17 May 2011 02:12:23 GMT
Author: yonik
Date: Tue May 17 02:12:22 2011
New Revision: 1103985

URL: http://svn.apache.org/viewvc?rev=1103985&view=rev
Log:
SOLR-2520: escape u2029 as well as u2028 to make valid javascript as well as JSON

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/solr/   (props changed)
    lucene/dev/branches/branch_3x/solr/CHANGES.txt
    lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/response/JSONResponseWriter.java
    lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/request/JSONWriterTest.java

Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1103985&r1=1103984&r2=1103985&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Tue May 17 02:12:22 2011
@@ -107,6 +107,10 @@ Bug Fixes
 * SOLR-2495: The JSON parser could hang on corrupted input and could fail
   to detect numbers that were too large to fit in a long.  (yonik)
 
+* SOLR-2520: Make JSON response format escape \u2029 as well as \u2028
+  in strings since those characters are not valid in javascript strings
+  (although they are valid in JSON strings).  (yonik)
+
 
 Other Changes
 ----------------------

Modified: lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/response/JSONResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/response/JSONResponseWriter.java?rev=1103985&r1=1103984&r2=1103985&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/response/JSONResponseWriter.java
(original)
+++ lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/response/JSONResponseWriter.java
Tue May 17 02:12:22 2011
@@ -618,7 +618,7 @@ class JSONWriter extends TextResponseWri
 
       for (int i=0; i<val.length(); i++) {
         char ch = val.charAt(i);
-        if ((ch > '#' && ch != '\\' && ch !=  '\u2028') || ch==' ') {
// fast path
+        if ((ch > '#' && ch != '\\' && ch < '\u2028') || ch == ' ')
{ // fast path
           writer.write(ch);
           continue;
         }
@@ -633,7 +633,10 @@ class JSONWriter extends TextResponseWri
           case '\t': writer.write('\\'); writer.write('t'); break;
           case '\b': writer.write('\\'); writer.write('b'); break;
           case '\f': writer.write('\\'); writer.write('f'); break;
-          case '\u2028': unicodeEscape(writer,ch); break;
+          case '\u2028': // fallthrough
+          case '\u2029':
+            unicodeEscape(writer,ch);
+            break;
           // case '/':
           default: {
             if (ch <= 0x1F) {

Modified: lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/request/JSONWriterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/request/JSONWriterTest.java?rev=1103985&r1=1103984&r2=1103985&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/request/JSONWriterTest.java
(original)
+++ lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/request/JSONWriterTest.java
Tue May 17 02:12:22 2011
@@ -72,12 +72,12 @@ public class JSONWriterTest extends Solr
 
     StringWriter buf = new StringWriter();
     NamedList nl = new NamedList();
-    nl.add("data1", "hello");
+    nl.add("data1", "he\u2028llo\u2029!");       // make sure that 2028 and 2029 are both
escaped (they are illegal in javascript)
     nl.add(null, 42);
     rsp.add("nl", nl);
 
     w.write(buf, req, rsp);
-    assertEquals(buf.toString(), "{\"nl\":[[\"data1\",\"hello\"],[null,42]]}");
+    assertEquals("{\"nl\":[[\"data1\",\"he\\u2028llo\\u2029!\"],[null,42]]}", buf.toString());
     req.close();
   }
   



Mime
View raw message