Skip to content

Preserve plus signs in JSONPointer URI fragments - #1090

Open
JimmyLiuJia wants to merge 2 commits into
stleary:masterfrom
JimmyLiuJia:fix/json-pointer-fragment-plus
Open

JimmyLiuJia wants to merge 2 commits into
stleary:masterfrom
JimmyLiuJia:fix/json-pointer-fragment-plus

Conversation

@JimmyLiuJia

@JimmyLiuJia JimmyLiuJia commented Oct 11, 2026 •

Copy link
Copy Markdown

With both "a+b" and "a b" in a document, query("#/a+b") currently returns the space-containing member. JSONPointer uses form decoding for URI fragments, so it converts a literal + into a space. Conversely, toURIFragment() emits spaces as + rather than %20.

Preserve literal plus signs during UTF-8 percent decoding and emit spaces as %20. This follows RFC 6901 section 6 and the URI fragment syntax in RFC 3986. The regressions cover colliding keys, %2B/%20/%252B, UTF-8, pointer escapes, and generated-fragment round trips.

Validation against the updated master:

  • All three fragment regression tests were verified to fail against the original implementation and pass after the fix.
  • On JDK 17, mvn clean verify -Dgpg.skip=true and mvn clean test -P test-strict-mode each complete with 818 passing tests, six existing skips, and zero failures/errors (824 tests reported).
  • On JDK 8, mvn clean test completes with the same 818 passing tests, six existing skips, and zero failures/errors (824 tests reported).
  • All 42 JSONPointer tests pass in each run, including the upstream tilde-escape regression and the three fragment regressions. Production sources compile with -source 1.6 -target 1.6 using JDK 8; no Java 6 runtime test is claimed.

AI assistance: OpenAI Codex assisted with the investigation, implementation, regression tests, conflict resolution, and this description.

@stleary

stleary commented Oct 11, 2026

Copy link
Copy Markdown
Owner

@JimmyLiuJia Please resolve conflicts in JSONPointerTest

@@ -1,287 +1,288 @@
package org.json;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you have inserted CRLFs throughout the file. Please restore the original formatting in this file, and potentially in JSONPointerTest.java

@sonarqubecloud

Copy link
Copy Markdown

@stleary

stleary commented Oct 11, 2026

Copy link
Copy Markdown
Owner

What problem does this code solve?
Fixes a problem with the use of plus signs in JSONPointer

Risks
Low

Changes to the Existing Behavior
Yes, but minimal.

Changes to the API
No

Will this require a new release?
No

Should the documentation be updated?
No, but release notes need to be added for all JSONPointer changes in the next release.
Going forward, all releases will include release notes.

Unit Tests
New unit tests were added

Refactoring
No

Review status
APPROVED

Starting 3-day comment window

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants