Skip to content

Commit

Permalink
[JENKINS-14827] Misinterpretation of "[...]".
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Aug 16, 2012
1 parent f5cb012 commit 71809a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
13 changes: 0 additions & 13 deletions src/main/jdk15/net/sf/json/JSONArray.java
Expand Up @@ -916,12 +916,7 @@ private static JSONArray _fromJSONTokener( JSONTokener tokener, JsonConfig jsonC
tokener.back();
Object v = tokener.nextValue( jsonConfig );
if( !JSONUtils.isFunctionHeader( v ) ){
if( v instanceof String && JSONUtils.mayBeJSON( (String) v ) ){
jsonArray.addValue( JSONUtils.DOUBLE_QUOTE + v + JSONUtils.DOUBLE_QUOTE,
jsonConfig );
}else{
jsonArray.addValue( v, jsonConfig );
}
fireElementAddedEvent( index, jsonArray.get( index++ ), jsonConfig );
}else{
// read params if any
Expand Down Expand Up @@ -2255,15 +2250,7 @@ private Object _processValue( Object value, JsonConfig jsonConfig ) {
return _fromJSONTokener( (JSONTokener) value, jsonConfig );
}else if( JSONUtils.isString( value ) ){
String str = String.valueOf( value );
if( JSONUtils.mayBeJSON( str ) ){
try{
return JSONSerializer.toJSON( str, jsonConfig );
}catch( JSONException jsone ){
return JSONUtils.stripQuotes( str );
}
}else{
return str;
}
}else if( JSONUtils.isNumber( value ) ){
JSONUtils.testValidity( value );
return JSONUtils.transformNumber( (Number) value );
Expand Down
11 changes: 0 additions & 11 deletions src/main/jdk15/net/sf/json/JSONObject.java
Expand Up @@ -893,24 +893,13 @@ private static JSONObject _fromJSONTokener( JSONTokener tokener, JsonConfig json
continue;
}
if( jsonPropertyFilter == null || !jsonPropertyFilter.apply( tokener, key, v ) ){
if( v instanceof String && JSONUtils.mayBeJSON( (String) v ) ){
value = JSONUtils.DOUBLE_QUOTE + v + JSONUtils.DOUBLE_QUOTE;
if( jsonObject.properties.containsKey( key ) ){
jsonObject.accumulate( key, value, jsonConfig );
firePropertySetEvent( key, value, true, jsonConfig );
}else{
jsonObject.element( key, value, jsonConfig );
firePropertySetEvent( key, value, false, jsonConfig );
}
}else{
if( jsonObject.properties.containsKey( key ) ){
jsonObject.accumulate( key, v, jsonConfig );
firePropertySetEvent( key, v, true, jsonConfig );
}else{
jsonObject.element( key, v, jsonConfig );
firePropertySetEvent( key, v, false, jsonConfig );
}
}
}
}else{
// read params if any
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/net/sf/json/TestJSONArray.java
Expand Up @@ -1421,4 +1421,9 @@ private void testJSONArray( Object array, String expected ) {
fail( jsone.getMessage() );
}
}

public void testMayBeJSON() {
assertEquals("[foo]", JSONArray.fromObject("[\"[foo]\"]").getString(0));
}

}
5 changes: 5 additions & 0 deletions src/test/java/net/sf/json/TestJSONObject.java
Expand Up @@ -1434,4 +1434,9 @@ public void testCanonicalWrite() throws Exception {
System.out.println(sw.toString());
assertEquals(sw.toString(),"[true,1,5.3,{\"key1\":\"1\",\"key2\":\"2\",\"key3\":\"3\",\"string\":\"123\\u000d\\u000a\\u0008\\u0009\\u000c\\\\\\\\u65E5\\\\u672C\\\\u8A9E\"}]");
}

public void testMayBeJSON() {
assertEquals("[foo]", JSONObject.fromObject("{x=\"[foo]\"}").getString("x"));
}

}

0 comments on commit 71809a8

Please sign in to comment.