Skip to content

org.json.XML.unescape("
"); throws org.json.JSONException: Invalid numeric character reference: 
 #1059

Closed

Description

@S-wald

org.json.XML.unescape("
"); throws org.json.JSONException: Invalid numeric character reference: 
 in version 20260522

Works in version 20251224.

Activity

  1. stleary commented on Jun 12, 2026

    @stleary
    Owner

    @S-wald Thanks for submitting this issue.

    Alternate form of the issue:
    // throws an exception after v20260522, but used to work in v20251224
    XML.toJSONObject("<a>&#10;</a>");

    In XML, the &#...; sequence defines a codepoint, not a numeric value. The codepoint 10 is a linefeed, which is not a valid JSON character. I believe it was fixed correctly in #1045.
    However, a mechanism can be provided to support legacy code that relies on the v20251224 behavior, for the special case of codepoints that evaluate to one of the common whitespace chars (TAB, LF, CR). Will this work for you?

  2. S-wald commented on Jun 12, 2026

    @S-wald
    Author

    @stleary IMHO org.json.XML.unescape should just unescape XML and output the whitespace char (e.g. '\n'). After that it may be escaped for JSON again.

  3. stleary commented on Jun 13, 2026

    @stleary
    Owner

    v20251224 behavior:
    Given: XML.toJSONObject("<a>&#10;</a>");

    &#10; is parsed to int 10 and converted to a string containing a linefeed, this value is stripped when trim() is called, so the resulting value is an empty string.

    @S-wald What is your use case? Is your code calling XML.unescape() directly?

  4. S-wald commented on Jun 23, 2026

    @S-wald
    Author

    We use XML.toJSONObject to convert some XML we get from some other system component.

  5. added a commit that references this issue on Jul 29, 2026
    94854a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions