Don't escape apostroph, it is inside a string
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Nov 2013 10:20:50 +0100
changeset 338edd0ccc8ae19
parent 330 e4b3840d4084
child 340 eda32ccb6882
Don't escape apostroph, it is inside a string
json-tck/src/main/java/net/java/html/json/tests/JSONTest.java
json/src/main/java/org/apidesign/html/json/impl/JSON.java
     1.1 --- a/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java	Fri Nov 22 10:49:23 2013 +0100
     1.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java	Tue Nov 26 10:20:50 2013 +0100
     1.3 @@ -108,6 +108,26 @@
     1.4              "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName();
     1.5      }
     1.6      
     1.7 +    @KOTest public void toJSONWithApostrophInABrowser() throws Throwable {
     1.8 +        Person p = Models.bind(new Person(), newContext());
     1.9 +        p.setSex(Sex.MALE);
    1.10 +        p.setFirstName("Jimmy 'Jim' Rambo");
    1.11 +
    1.12 +        
    1.13 +        final String txt = p.toString();
    1.14 +        Object json;
    1.15 +        try {
    1.16 +            json = parseJSON(txt);
    1.17 +        } catch (Throwable ex) {
    1.18 +            throw new IllegalStateException("Can't parse " + txt).initCause(ex);
    1.19 +        }
    1.20 +        
    1.21 +        Person p2 = JSON.read(newContext(), Person.class, json);
    1.22 +        
    1.23 +        assert p2.getFirstName().equals(p.getFirstName()) : 
    1.24 +            "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName();
    1.25 +    }
    1.26 +    
    1.27      @OnReceive(url="{url}")
    1.28      static void fetch(Person p, JSONik model) {
    1.29          model.setFetched(p);
     2.1 --- a/json/src/main/java/org/apidesign/html/json/impl/JSON.java	Fri Nov 22 10:49:23 2013 +0100
     2.2 +++ b/json/src/main/java/org/apidesign/html/json/impl/JSON.java	Tue Nov 26 10:20:50 2013 +0100
     2.3 @@ -89,7 +89,6 @@
     2.4              for (int i = 0; i < len; i++) {
     2.5                  char ch = s.charAt(i);
     2.6                  switch (ch) {
     2.7 -                    case '\'': sb.append("\\\'"); break;
     2.8                      case '\"': sb.append("\\\""); break;
     2.9                      case '\n': sb.append("\\n"); break;
    2.10                      case '\r': sb.append("\\r"); break;