Fixed special character handling in DataPath
This commit is contained in:
parent
676ce6a33f
commit
a2694af70f
2 changed files with 14 additions and 3 deletions
|
|
@ -81,14 +81,15 @@ public class DataNodePath {
|
||||||
operator = c;
|
operator = c;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '\"':
|
||||||
case '\'': // Read in everything until next quote
|
case '\'': // Read in everything until next quote
|
||||||
buffer.append(c);
|
for (i++; i < path.length(); i++) {
|
||||||
for (; i < path.length(); i++) {
|
|
||||||
char c2 = path.charAt(i);
|
char c2 = path.charAt(i);
|
||||||
|
|
||||||
buffer.append(c2);
|
|
||||||
if (c2 == c)
|
if (c2 == c)
|
||||||
break;
|
break;
|
||||||
|
buffer.append(c2);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,16 @@ public class DataNodePathTest {
|
||||||
assertThrows(IllegalArgumentException.class, () -> DataNodePath.search("11", new DataNode(DataNode.DataType.Map)));
|
assertThrows(IllegalArgumentException.class, () -> DataNodePath.search("11", new DataNode(DataNode.DataType.Map)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specialChar() {
|
||||||
|
String json = "{'child1.1': 'test', 'child2': {'child3': 'banana'}}";
|
||||||
|
DataNode rootNode = JSONParser.read(json);
|
||||||
|
|
||||||
|
assertNull(DataNodePath.search("$.child1.1", rootNode));
|
||||||
|
assertEquals("test", DataNodePath.search("$.'child1.1'", rootNode).getString());
|
||||||
|
assertEquals("test", DataNodePath.search("$.\"child1.1\"", rootNode).getString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mapPath() {
|
public void mapPath() {
|
||||||
String json = "{child1: 'test', child2: {child3: 'banana'}}";
|
String json = "{child1: 'test', child2: {child3: 'banana'}}";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue