Browse Source

String quote style is serialized #154

pull/158/head
Kalle Stenflo 9 years ago
parent
commit
4040634a71
  1. 12
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java
  2. 6
      json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java

12
json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java

@ -395,11 +395,18 @@ public abstract class ValueNode {
public static class StringNode extends ValueNode {
private final String string;
private boolean useSingleQuote = true;
private StringNode(CharSequence charSequence, boolean escape) {
if(charSequence.length() > 1){
if(charSequence.charAt(0) == '\'' && charSequence.charAt(charSequence.length()-1) == '\''){
char open = charSequence.charAt(0);
char close = charSequence.charAt(charSequence.length()-1);
if(open == '\'' && close == '\''){
charSequence = charSequence.subSequence(1, charSequence.length()-1);
} else if(open == '"' && close == '"'){
charSequence = charSequence.subSequence(1, charSequence.length()-1);
useSingleQuote = false;
}
}
string = escape ? Utils.unescape(charSequence.toString()) : charSequence.toString();
@ -436,7 +443,8 @@ public abstract class ValueNode {
@Override
public String toString() {
return "'" + Utils.escape(string, true) + "'";
String quote = useSingleQuote ? "'" : "\"";
return quote + Utils.escape(string, true) + quote;
}
@Override

6
json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java

@ -48,6 +48,12 @@ public class FilterCompilerTest {
}
@Test
public void string_quoute_style_is_serialized() {
assertThat(compile("[?('apa' == 'apa')]").toString()).isEqualTo("[?('apa' == 'apa')]");
assertThat(compile("[?('apa' == \"apa\")]").toString()).isEqualTo("[?('apa' == \"apa\")]");
}
@Test
public void invalid_filters_does_not_compile() {

Loading…
Cancel
Save