Skip to content

Commit

Permalink
Merge pull request #18 from sacha-cs/fix/lazy-array-to-string-escaped…
Browse files Browse the repository at this point in the history
…-chars

Fix toString on LazyArray which did not conserve escaped chars
  • Loading branch information
kasperjj authored Jun 29, 2018
2 parents 6f048bf + 050ba3c commit 7f23ef1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/me/doubledutch/lazyjson/LazyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ protected String serializeElementToString(){
buf.append(new LazyObject(pointer).toString());
}else if(pointer.type==LazyNode.ARRAY){
buf.append(new LazyArray(pointer).toString());
}else if(pointer.type==LazyNode.VALUE_STRING || pointer.type==LazyNode.VALUE_ESTRING){
}else if(pointer.type==LazyNode.VALUE_STRING){
buf.append("\"");
buf.append(pointer.getStringValue());
buf.append("\"");
}else if (pointer.type==LazyNode.VALUE_ESTRING){
buf.append("\"");
buf.append(pointer.getRawStringValue());
buf.append("\"");
}else if(pointer.type==LazyNode.VALUE_TRUE){
buf.append("true");
}else if(pointer.type==LazyNode.VALUE_FALSE){
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/me/doubledutch/lazyjson/LazyArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,12 @@ public void testNickSample() throws LazyException{
assertNotNull(obj2);
assertEquals(obj.getString("[]"),"{}");
}

@Test
public void testSerializeStringWithEscapedQuotes() {
LazyArray lazyArray = new LazyArray();
lazyArray.put("\"foo\" bar");
lazyArray.put("baz");
assertEquals("[\"\\\"foo\\\" bar\",\"baz\"]", lazyArray.toString());
}
}

0 comments on commit 7f23ef1

Please sign in to comment.