JSONML decodes text entities twice with keepStrings enabled

Open Beginner friendly
#1,079 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Start in JSONML.parse(), focusing on the keepStrings branch, and compare it with XMLTokener.nextContent() and XML.unescape(), which the issue identifies as the relevant paths. Reproduce the supplied Java example, then verify that keepStrings preserves the text node as "<" and that converting the result back to XML preserves the original text.

Written by the indexing model from the issue text.

Description

JSONML decodes text nodes twice when keepStrings is enabled. Attributes and the default mode decode the same input once.

Reproduced on release 20260814 and current master (874673575807723d58bbec9ff1985668742940ce), with Java 17.0.20:

import org.json.JSONML;

String xml = "<p title=\"&amp;lt;\">&amp;lt;</p>";
System.out.println(JSONML.toJSONArray(xml, false));
System.out.println(JSONML.toJSONArray(xml, true));

Output:

["p",{"title":"&lt;"},"&lt;"]
["p",{"title":"&lt;"},"<"]

The second result should also contain "&lt;" as its text node. Enabling keepStrings should affect type conversion, not the text itself. toJSONObject(xml, true) has the same behavior, and converting the result back to XML changes the original text.

XMLTokener.nextContent() already decodes entities, but the keepStrings branch in JSONML.parse() calls XML.unescape() again. This looks like a remaining case from #362, which removed the extra decoding for JSONML attributes and the XML conversion paths.

Dominant language
Java
Stars
4.7k
Forks
2.6k
Avg merge
6d 20h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stleary/JSON-java

All issues in stleary/JSON-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.