JSONML decodes text entities twice with keepStrings enabled

未關閉 適合新手
#1,079 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java
領域
backend

研究方向

從 JSONML.parse() 開始,著重檢視 keepStrings 分支,並將其與 XMLTokener.nextContent() 和 XML.unescape() 比較,issue 將它們識別為相關路徑。重現所提供的 Java 範例,然後驗證 keepStrings 會將文字節點保留為 "<",以及將結果轉回 XML 後仍會保留原始文字。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
Java
星號
4.7k
分支
2.6k
平均合併
6 天 20 小時
30 天內合併 PR
2

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

stleary/JSON-java 的其他 Issue

查看 stleary/JSON-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。