Skip to content

Validate XML numeric character references before string construction#1046

Open
yuki-matsuhashi wants to merge 1 commit intostleary:masterfrom
yuki-matsuhashi:master
Open

Validate XML numeric character references before string construction#1046
yuki-matsuhashi wants to merge 1 commit intostleary:masterfrom
yuki-matsuhashi:master

Conversation

@yuki-matsuhashi
Copy link
Contributor

Fixes #1045

This PR validates XML numeric character references before string construction.

Changes in this PR:

  • reject XML-invalid numeric character references with JSONException
  • add regression tests for out-of-range hex and decimal values
  • add regression coverage for surrogate values and attribute values

Note

#1045 focused on out-of-range values such as �, which raised an uncaught runtime exception before this fix. Surrogate values such as � did not reproduce the same exception in my testing, but they are still invalid XML character references and are rejected by the same validation.

@sonarqubecloud
Copy link

@stleary
Copy link
Owner

stleary commented Mar 24, 2026

What problem does this code solve?
XML code throws an uncontrolled exception when parsing invalid codepoints to JSON. This fix replaced the exception with a JSONException

Does the code still compile with Java6?
Yes

Risks
Low

Changes to the API?
Yes, but just in the type of exception thrown

Will this require a new release?
No

Should the documentation be updated?
No

Does it break the unit tests?
No, new unit tests were added.

Was any code refactored in this commit?
No

Review status
APPROVED

Starting 3-day comment window

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.

XML.toJSONObject() throws uncaught IllegalArgumentException for out-of-range numeric character references

2 participants