Merge pull request #1083 from DarkLight606/fix/1082
Fix a parsing error in JSONPointer.toURIFragment()
This commit is contained in:
@@ -276,7 +276,7 @@ public class JSONPointer {
|
|||||||
try {
|
try {
|
||||||
StringBuilder rval = new StringBuilder("#");
|
StringBuilder rval = new StringBuilder("#");
|
||||||
for (String token : this.refTokens) {
|
for (String token : this.refTokens) {
|
||||||
rval.append('/').append(URLEncoder.encode(token, ENCODING));
|
rval.append('/').append(URLEncoder.encode(escape(token), ENCODING));
|
||||||
}
|
}
|
||||||
return rval.toString();
|
return rval.toString();
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
|||||||
@@ -219,9 +219,29 @@ public class JSONPointerTest {
|
|||||||
assertEquals("#/c%25d", new JSONPointer("/c%d").toURIFragment());
|
assertEquals("#/c%25d", new JSONPointer("/c%d").toURIFragment());
|
||||||
assertEquals("#/e%5Ef", new JSONPointer("/e^f").toURIFragment());
|
assertEquals("#/e%5Ef", new JSONPointer("/e^f").toURIFragment());
|
||||||
assertEquals("#/g%7Ch", new JSONPointer("/g|h").toURIFragment());
|
assertEquals("#/g%7Ch", new JSONPointer("/g|h").toURIFragment());
|
||||||
assertEquals("#/m%7En", new JSONPointer("/m~n").toURIFragment());
|
assertEquals("#/m%7E0n", new JSONPointer("/m~n").toURIFragment());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toURIFragmentEscaping() {
|
||||||
|
JSONPointer pointer = JSONPointer.builder()
|
||||||
|
.append("obj")
|
||||||
|
.append("other~key").append("another/key")
|
||||||
|
.append(0)
|
||||||
|
.build();
|
||||||
|
assertEquals("#/obj/other%7E0key/another%7E1key/0", pointer.toURIFragment());
|
||||||
|
assertEquals("val", new JSONPointer(pointer.toURIFragment()).queryFrom(document));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toURIFragmentRoundTrip() {
|
||||||
|
JSONObject object = new JSONObject().put("~1", "tilde one").put("/", "slash");
|
||||||
|
JSONPointer tildeOne = JSONPointer.builder().append("~1").build();
|
||||||
|
JSONPointer slash = JSONPointer.builder().append("/").build();
|
||||||
|
assertEquals("tilde one", object.query(tildeOne.toURIFragment()));
|
||||||
|
assertEquals("slash", object.query(slash.toURIFragment()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tokenListIsCopiedInConstructor() {
|
public void tokenListIsCopiedInConstructor() {
|
||||||
JSONPointer.Builder b = JSONPointer.builder().append("key1");
|
JSONPointer.Builder b = JSONPointer.builder().append("key1");
|
||||||
|
|||||||
Reference in New Issue
Block a user