Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 398973
Collapse All | Expand All

(-)a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/protocol/Operation.java (-2 / +1 lines)
Lines 46-53 Link Here
46
46
47
  void appendProperties( Map<String, Object> properties ) {
47
  void appendProperties( Map<String, Object> properties ) {
48
    if( properties != null && !properties.isEmpty() ) {
48
    if( properties != null && !properties.isEmpty() ) {
49
      Set<String> keySet = properties.keySet();
49
      for( String key : properties.keySet() ) {
50
      for( String key : keySet ) {
51
        appendProperty( key, JsonUtil.createJsonValue( properties.get( key ) ) );
50
        appendProperty( key, JsonUtil.createJsonValue( properties.get( key ) ) );
52
      }
51
      }
53
    }
52
    }
(-)a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonObject.java (-1 / +2 lines)
Lines 49-54 Link Here
49
    }
49
    }
50
  }
50
  }
51
51
52
  @Override
52
  public String toString() {
53
  public String toString() {
53
    String tail = count == 0 ? "}" : "\n}";
54
    String tail = count == 0 ? "}" : "\n}";
54
    return buffer.toString() + tail;
55
    return buffer.toString() + tail;
Lines 56-62 Link Here
56
57
57
  private void doAppend( String key, String valueStr ) {
58
  private void doAppend( String key, String valueStr ) {
58
    buffer.append( count == 0 ? "\n" : ",\n" );
59
    buffer.append( count == 0 ? "\n" : ",\n" );
59
    buffer.append( quoteAndEscapeString( key ) );
60
    appendQuotedAndEscapedString( buffer, key );
60
    buffer.append( ": " );
61
    buffer.append( ": " );
61
    buffer.append( valueStr );
62
    buffer.append( valueStr );
62
    count++;
63
    count++;
(-)a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonValue.java (-22 / +29 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2012 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2008, 2013 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 60-101 Link Here
60
  }
60
  }
61
61
62
  static String quoteAndEscapeString( String string ) {
62
  static String quoteAndEscapeString( String string ) {
63
    StringBuilder resultBuffer = new StringBuilder();
63
    StringBuilder buffer = new StringBuilder( string.length() + 2 );
64
    resultBuffer.append( '"' );
64
    appendQuotedAndEscapedString( buffer, string );
65
    resultBuffer.append( escapeString( string ) );
65
    return buffer.toString();
66
    resultBuffer.append( '"' );
67
    return resultBuffer.toString();
68
  }
66
  }
69
67
70
  static String escapeString( String string ) {
68
  static void appendQuotedAndEscapedString( StringBuilder buffer, String string ) {
71
    StringBuilder resultBuffer = new StringBuilder();
69
    buffer.append( '"' );
72
    int length = string.length();
70
    appendEscapedString( buffer, string );
71
    buffer.append( '"' );
72
  }
73
74
  static void appendEscapedString( StringBuilder buffer, String string ) {
75
    char[] chars = string.toCharArray();
76
    int length = chars.length;
73
    for( int i = 0; i < length; i++ ) {
77
    for( int i = 0; i < length; i++ ) {
74
      char ch = string.charAt( i );
78
      char ch = chars[ i ];
75
      if( ch == '"' || ch == '\\' ) {
79
      if( ch == '"' || ch == '\\' ) {
76
        resultBuffer.append( '\\' );
80
        buffer.append( '\\' );
77
        resultBuffer.append( ch );
81
        buffer.append( ch );
78
      } else if( ch == '\n' ) {
82
      } else if( ch == '\n' ) {
79
        resultBuffer.append( "\\n" );
83
        buffer.append( '\\' );
84
        buffer.append( 'n' );
80
      } else if( ch == '\r' ) {
85
      } else if( ch == '\r' ) {
81
        resultBuffer.append( "\\r" );
86
        buffer.append( '\\' );
87
        buffer.append( 'r' );
82
      } else if( ch == '\t' ) {
88
      } else if( ch == '\t' ) {
83
        resultBuffer.append( "\\t" );
89
        buffer.append( '\\' );
90
        buffer.append( 't' );
84
      } else if( ch == '\u2028' ) {
91
      } else if( ch == '\u2028' ) {
85
        resultBuffer.append( "\\u2028" );
92
        buffer.append( "\\u2028" );
86
      } else if( ch == '\u2029' ) {
93
      } else if( ch == '\u2029' ) {
87
        resultBuffer.append( "\\u2029" );
94
        buffer.append( "\\u2029" );
88
      } else if( ch >= CONTROL_CHARACTERS_START && ch <= CONTROL_CHARACTERS_END ) {
95
      } else if( ch >= CONTROL_CHARACTERS_START && ch <= CONTROL_CHARACTERS_END ) {
89
        resultBuffer.append( "\\u00" );
96
        buffer.append( "\\u00" );
90
        if( ch <= 0x000f ) {
97
        if( ch <= 0x000f ) {
91
          resultBuffer.append( "0" );
98
          buffer.append( '0' );
92
        }
99
        }
93
        resultBuffer.append( Integer.toHexString( ch ) );
100
        buffer.append( Integer.toHexString( ch ) );
94
      } else {
101
      } else {
95
        resultBuffer.append( ch );
102
        buffer.append( ch );
96
      }
103
      }
97
    }
104
    }
98
    return resultBuffer.toString();
99
  }
105
  }
100
106
101
  private static class JsonPrimitive extends JsonValue {
107
  private static class JsonPrimitive extends JsonValue {
Lines 106-111 Link Here
106
      this.value = value;
112
      this.value = value;
107
    }
113
    }
108
114
115
    @Override
109
    public String toString() {
116
    public String toString() {
110
      return value;
117
      return value;
111
    }
118
    }
(-)a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/theme/JsonValue_Test.java (-8 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2012 Innoopract Informationssysteme GmbH and others.
2
 * Copyright (c) 2008, 2013 Innoopract Informationssysteme GmbH and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 82-109 Link Here
82
  @Test
82
  @Test
83
  public void testEscapeStringWithQuotes() {
83
  public void testEscapeStringWithQuotes() {
84
    // escape a\b -> "a\\b"
84
    // escape a\b -> "a\\b"
85
    assertEquals( "a\\\\b", JsonValue.escapeString( "a\\b" ) );
85
    assertEquals( "a\\\\b", escapeString( "a\\b" ) );
86
    // escape a"b -> "a\"b"
86
    // escape a"b -> "a\"b"
87
    assertEquals( "a\\\"b", JsonValue.escapeString( "a\"b" ) );
87
    assertEquals( "a\\\"b", escapeString( "a\"b" ) );
88
    // escape a\"b\" -> "a\\\"b\\\""
88
    // escape a\"b\" -> "a\\\"b\\\""
89
    assertEquals( "a\\\\\\\"b\\\\\\\"", JsonValue.escapeString( "a\\\"b\\\"" ) );
89
    assertEquals( "a\\\\\\\"b\\\\\\\"", escapeString( "a\\\"b\\\"" ) );
90
  }
90
  }
91
91
92
  @Test
92
  @Test
93
  public void testEscapeStringWithNewLines() {
93
  public void testEscapeStringWithNewLines() {
94
    assertEquals( "a\\n", JsonValue.escapeString( "a\n" ) );
94
    assertEquals( "a\\n", escapeString( "a\n" ) );
95
    assertEquals( "a\\r\\nb", JsonValue.escapeString( "a\r\nb" ) );
95
    assertEquals( "a\\r\\nb", escapeString( "a\r\nb" ) );
96
  }
96
  }
97
97
98
  @Test
98
  @Test
99
  public void testEscapeStringWithTabs() {
99
  public void testEscapeStringWithTabs() {
100
    assertEquals( "a\\tb", JsonValue.escapeString( "a\tb" ) );
100
    assertEquals( "a\\tb", escapeString( "a\tb" ) );
101
  }
101
  }
102
102
103
  @Test
103
  @Test
104
  public void testEscapeStringWithSpecialCharacters() {
104
  public void testEscapeStringWithSpecialCharacters() {
105
    String expected = "\\u2028foo\\u2029";
105
    String expected = "\\u2028foo\\u2029";
106
    assertEquals( expected, JsonValue.escapeString( "\u2028foo\u2029" ) );
106
    assertEquals( expected, escapeString( "\u2028foo\u2029" ) );
107
  }
107
  }
108
108
109
  @Test
109
  @Test
Lines 126-129 Link Here
126
    assertEquals( "\"hel\\u000flo\"", JsonValue.valueOf( String.valueOf( data ) ).toString() );
126
    assertEquals( "\"hel\\u000flo\"", JsonValue.valueOf( String.valueOf( data ) ).toString() );
127
  }
127
  }
128
128
129
  private static String escapeString( String string ) {
130
    StringBuilder result = new StringBuilder();
131
    JsonValue.appendEscapedString( result, string );
132
    return result.toString();
133
  }
134
129
}
135
}

Return to bug 398973