566 Commits
Author SHA1 Message Date
Sean Leary 2cd0a8c211 Merge pull request #1093 from Lyin-OTTF/fix/xml-serialize-escape-whitespace
Fix TAB/LF/CR escape when serializing to XML
2026-10-31 08:34:32 -05:00
Sean Leary bc90ee497b Merge pull request #1095 from Lyin-OTTF/fix/gh-1076-fromjson-binding-javadoc
Update Javadocs for fromJson()
2026-10-31 08:33:12 -05:00
Lyin-OTTF 88b6be9f84 Clarify fromJson(Class) Javadoc: type registry does not exist
The fromJson(Class) Javadoc claimed that only classes "explicitly supported
and registered within the JSONObject context" can be deserialized, and
declared an IllegalArgumentException for classes outside that set. No such
registry exists: fromJson instantiates any class with a no-arg constructor and
writes every non-static declared field whose name matches a JSON key, widening
access with setAccessible(true). Private and transient fields are populated,
and JSONPropertyIgnore does not apply because it only suppresses the bean to
JSONObject direction.

The binding rules are already released, so changing them here would break
existing users. Instead document what actually happens, point out that binding
is driven by whatever keys the JSON contains, and replace the non-existent
IllegalArgumentException with the JSONException the method really throws.

Adds JSONObjectTest#jsonObjectParseFromJson_10 to pin the current binding
behavior so the documentation cannot drift from the implementation again. The
test bean is named FromJsonKeyBindingExample and its fields spell out how they
are declared (privateString, privateBoolean, transientString,
ignoredGetterBoolean), so the test reads as a binding example rather than as a
scenario.

Fixes #1076
2026-10-26 08:38:38 +08:00
Lyin-OTTF fea3a2ce32 Escape TAB/LF/CR again when serializing to XML
XML.mustEscape() is shared by XML.escape() (serialization) and
XMLTokener.unescapeEntity() (parsing), but the two callers need opposite
answers for #x9/#xA/#xD. #1070 added those codepoints to the valid-range
clause to fix unescape("
"), which also stopped XML.toString() and
JSONML.toString() from escaping literal TAB, LF and CR. Literal
occurrences of these characters are subject to whitespace normalization
by conforming XML parsers, so a value like "Lettuce\nTomato" loses its
line breaks when the generated XML is read back by any standard parser.
This regressed #1092.

Split the two concerns: mustEscape() returns true for every ISO control
character again (serialization), and the new isValidXmlCharacter() keeps
the previous numeric-reference validation for the parsing path, so 	,

 and 
 are still accepted (#1059/#1070 behaviour unchanged).

isValidXmlCharacter() stays as strict as before for the C1 control
characters (#x7F-#x9F): they fall inside [#x20-#xD7FF] and are legal XML
1.0 characters, but this library has always rejected references to them,
and widening the range here would silently change what XML.toJSONObject
accepts. Only the serialization of TAB/LF/CR changes.

Fixes #1092
2026-10-26 08:35:09 +08:00
labkey-jeckels 293bbf65d3 Share repeated object keys within a parse (#1091) 2026-10-20 09:54:00 -07:00
JimmyLiuJia 4713079d13 Merge master and resolve JSONPointerTest conflict 2026-10-11 23:41:08 +08:00
Sean Leary 406abf8b76 Merge pull request #1088 from fahadaldajani92/test/jsonpointer-issue-1081
test: cover literal tilde tokens in JSONPointer
2026-10-11 08:39:01 -05:00
Sean Leary 5e9b4f4e27 Merge pull request #1087 from PHJ2000/fix-properties-defaults-only
Fix Property enumeration without local entries
2026-10-11 08:33:39 -05:00
JimmyLiuJia 564acf4eb1 Preserve plus signs in JSONPointer URI fragments 2026-10-11 16:21:40 +08:00
Sean Leary 6527427aad Merge pull request #1085 from Boulea7/fix/jsonml-keep-strings-entities
Fix JSONML text double decoding with keepStrings
2026-10-08 10:16:18 -05:00
Fahad Al-Dajani 23bc68f227 test: cover literal tilde tokens in JSONPointer 2026-10-08 16:55:26 +03:00
PHJ2000 3d2f7e07ec Preserve inherited properties without local entries 2026-10-05 18:17:59 +09:00
boulea7 f3c83d8349 Fix JSONML text double decoding with keepStrings 2026-10-02 18:18:04 +08:00
안승현 d38bff8957 Extract childNodes constant in JSONML
Replace the four repeated "childNodes" literals with a private
static final constant.

Address SonarQube rule java:S1192 without changing parsing behavior.
2026-10-01 17:15:16 +09:00
안승현 5dfa60ba0a Fix reserved childNodes attribute check in JSONML
JSONML object-form parsing uses "childNodes" to store child elements,
but the reserved-attribute check incorrectly used "childNode".

This rejected ordinary "childNode" attributes while accepting
"childNodes" attributes, whose values could then be overwritten
by the element's children.

Correct the reserved-attribute check to use "childNodes" and add
JUnit 4 regression tests covering:
- Rejection of reserved "childNodes" attributes in object-form parsing
- Preservation of ordinary "childNode" attributes and child content
- Continued rejection of reserved "tagName" attributes
- Preservation of both attribute names in array-form parsing

Verify each scenario with keepStrings enabled and disabled.

Validation:
- All 40 JSONML tests pass
- Full test suite: 807 passed, 6 skipped on Java 11 with Gradle 8.13
- Both bug regression tests fail against the original implementation

Fixes #1080
2026-10-01 16:55:38 +09:00
Denys Khalitov f875ab2fc7 Escape ~ and / in JSONPointer.toURIFragment()
toURIFragment() URL-encoded each reference token but skipped the ~0/~1
escaping from RFC 6901. Tokens are stored as literal key names, so a key
containing / or ~ produced a fragment that parsed back to a different
pointer. Apply escape() before encoding, as toString() already does.

Fixes #1082
2026-09-26 17:19:47 +03:00
Sean Leary b55c69e650 Merge pull request #1078 from jakezwang/fix/json-pointer-double-unescape
Decode JSONPointer tokens once only
2026-09-23 12:09:16 -05:00
Jake Wang 775c98ea41 Avoid decoding JSON Pointer tokens twice 2026-09-18 20:10:16 -04:00
sajad mahmoodifar 9f3b527d9f fix: restore tokener configuration after parsing 2026-09-18 16:53:59 +03:30
sajad mahmoodifar 0ae8d5ab4f fix: apply explicit parser configuration
Fixes #945
2026-09-18 13:25:36 +03:30
XIAYM-gh a25f83a0e4 Strip JSONTokener#isAtStart() 2026-09-11 03:57:03 +08:00
XIAYM-gh 359b43d8df Apply corner-case fixes under instruction 2026-09-04 08:09:14 +08:00
XIAYM-gh bcbbc89568 Fixes corner case where strict mode isn't working when JSONTokener's next() and back() are called first 2026-09-02 20:31:40 +08:00
Sean Leary 4f859fdf3b Merge pull request #1072 from mechko/1071-xml-tostring-name-validation
#1071: reject invalid XML element names in XML.toString (CWE-91)
2026-08-24 12:22:44 -05:00
Mirko SwillusandClaude 3dd0ec02f2 #1071: narrow tag-name check to XML metachars only
Per review on #1072: reject only < > & " ' / in element names to
close the CWE-91 injection vector, and drop the full XML 1.0 Name
validation to preserve backwards compatibility for callers that
emit non-well-formed but non-injecting tag names.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01MTGnYg5v1QxaqqfDKHKTVr
2026-08-20 17:14:07 +02:00
Mirko SwillusandClaude 6b993e2e47 #1071: extract inRange helper to satisfy Sonar S3776
isXmlNameStart's alternating &&/|| chain scored cognitive complexity 28.
Extracting inRange(cp, lo, hi) collapses it to a flat || sequence and
keeps the range list 1:1 with the XML 1.0 NameStartChar production.
isXmlNameChar updated the same way. No behaviour change.

Co-Authored-By: Claude <[email protected]>
2026-07-24 10:57:24 +02:00
Mirko SwillusandClaude e2cfb5a641 #1071: reject invalid XML element names in XML.toString (CWE-91)
XML.toString emitted JSONObject keys verbatim as tag names, so a key
containing '<', '>' or '/' broke out of its element and injected
arbitrary sibling structure into the output. Per #294/#123 the agreed
approach is to throw on invalid input rather than mangle it.

- Add mustBeXmlName / isXmlNameStart / isXmlNameChar implementing the
  XML 1.0 (5th ed.) Name production, code-point aware.
- Validate tagName at method entry and each key at the top of the key
  loop (skipping the cDataTagName sentinel).
- Rewrite XMLTest.shouldHandleIllegalJSONNodeNames and
  XMLConfigurationTest.shouldHandleIllegalJSONNodeNames (previously
  documenting the pass-through behaviour) to assert the throw.
- Add XMLTest.toStringRejectsElementInjectionInKey covering the #1071
  payload and an invalid caller-supplied tagName.
- Add XMLTest.toStringAcceptsValidXmlNames covering hyphen/dot/
  underscore/colon, Latin-1 letters, and the cDataTagName sentinel.

Fixes #1071. Also resolves the long-standing well-formedness question
in #166 / #294 / #308.

Co-Authored-By: Claude <[email protected]>
2026-07-23 14:36:42 +02:00
dong0713 94854a1dfa Fix XML.unescape rejecting valid whitespace numeric character references
XML.mustEscape() is shared by both XML.escape() (serialization) and
XMLTokener.unescapeEntity() (deserialization). While the method's Javadoc
and comment quote the W3C XML 1.0 valid-character range
(#x9 | #xA | #xD | [#x20-#xD7FF] | ...), the implementation only checked
[#x20-#xD7FF] in its range clause, omitting #x9/#xA/#xD.

Although the ISO-control clause excluded those three codepoints, the
negated range clause still marked them as 'must escape', so unescapeEntity()
threw JSONException for the XML-allowed control characters TAB, LF and CR.

This broke XML.unescape("&#10;") and XML.toJSONObject("<a>&#10;</a>"),
both of which worked in v20251224 and regressed after #1045 (v20260522).

Align the range clause with the W3C spec by explicitly allowing #x9, #xA
and #xD, matching the comment that was already documented.

Fixes #1059
2026-07-20 17:42:02 +08:00
Sean Leary da757c6656 pre-release-20260719 oops forgot to update new unit tests for strict mode 2026-07-19 13:48:18 -05:00
Sean Leary 9953b76050 max-number-length-config sonarqube fixes 2026-07-16 13:23:39 -05:00
Mirko SwillusandClaude 703ac34a55 #1063: add JSONParserConfiguration overloads for getBigInteger/optBigInteger
Per review on #1067:
- objectToBigInteger(val, dflt, JSONParserConfiguration) uses
  cfg.getMaxNumberLength() for the digit-count guard; -1 disables it.
  Existing 2-arg form delegates with a default config.
- New public overloads on JSONObject and JSONArray:
  getBigInteger(key, cfg) / optBigInteger(key, dflt, cfg).
  Existing methods delegate with a default config.
- objectToBigDecimal left unchanged (no expansion path; agreed on PR).
- Tests cover default (1000), raised (2000), lowered (5), disabled (-1),
  null config, and JSONArray overloads.

Co-Authored-By: Claude <[email protected]>
2026-07-16 11:42:40 +02:00
Mirko SwillusandClaude e40d933d50 #1063: add comment to expected-exception catch block (SonarCloud java:S108)
Co-Authored-By: Claude <[email protected]>
2026-07-14 13:36:46 +02:00
Mirko SwillusandClaude fce83c91bb #1063: bound BigDecimal->BigInteger expansion in objectToBigInteger
Completes the CVE-2026-59171 fix started in ab92bb9 / #1065. The
1000-char length guard in stringToValue admits short exponent-notation
literals (e.g. 1e100000000, 11 chars) which are stored compactly as
BigDecimal and only expand when getBigInteger/optBigInteger calls
BigDecimal.toBigInteger(), materialising ~10^8 digits and stalling the
thread or throwing OOM.

Guard both toBigInteger() sites in objectToBigInteger by rejecting any
BigDecimal whose integer part would exceed
ParserConfiguration.DEFAULT_MAX_NUMBER_LENGTH decimal digits
(precision() - scale(), both O(1) reads). Returns defaultValue on
overflow, matching the method's existing behaviour for non-finite and
unparseable values.

Covers JSONObject.getBigInteger/optBigInteger and
JSONArray.getBigInteger/optBigInteger (all delegate to this helper).

Adds JSONObjectTest.getBigIntegerHugeExponentReturnsDefault with a 5s
timeout so a regression fails fast rather than hanging CI.

Co-Authored-By: Claude <[email protected]>
2026-07-14 11:59:27 +02:00
Sean Leary 90563eb877 1063-option-3 parserConfig set max len 2026-07-13 15:33:12 -05:00
Damien Warren ab92bb9088 Fixes CVE-2026-59171 2026-07-03 09:21:58 -07:00
Sean Leary c91d821dbe Merge pull request #1062 from Fahmida-Hossain-Charu/pr/refactor-cdl-row-serialization
Refactor CDL row serialization for readability
2026-06-21 07:09:27 -05:00
Fahmida-Hossain-Charu 8353b59fa0 Address CDL row serialization review comments 2026-06-17 17:59:07 +06:00
Fahmida-Hossain-Charu 26ee6eb25a Refactor CDL row serialization 2026-06-17 04:17:48 +06:00
Sean Leary ad26e94274 restore-lenient-jsonarray fix some sonarcube issues 2026-06-15 20:56:17 -05:00
Sean Leary c073157a61 restore-lenient-jsonarray initial commit 2026-06-15 16:43:46 -05:00
Sean Leary d84fa1af88 docs-and-warnings-cleanup cleanup some doc files, update pom for deployment, fix some JSONObject warnings 2026-05-29 10:38:42 -05:00
Sean Leary 649598338f update-security-md-with-key new security.md file, also fixed 1000 level jsonarray test that fails on my laptop 2026-05-11 11:54:52 -05:00
Yuki Matsuhashi 1877069780 Validate XML numeric character references before string construction 2026-03-24 04:22:50 +09:00
Yuki Matsuhashi 039f331d7d Add comment for empty test constructor 2026-03-13 01:54:58 +09:00
Yuki Matsuhashi 94e340002b Ignore static fields in JSONObject.fromJson() 2026-03-13 01:23:59 +09:00
Sean Leary a37aa69480 Merge pull request #1039 from pratiktiwari13/bugfix/empty-force-list
Fixes the issue of losing the array if an empty forceList element or a tag is in the middle or the end
2026-02-03 11:15:58 -06:00
Pratik Tiwari 510a03ac36 Fixes #1040, Aligns non-forceList behaviour with forceList 2026-01-31 10:34:24 +05:30
Sean Leary 538afc3d78 Merge pull request #1038 from OwenSanzas/fix-xmltokener-unescapeentity
Fix input validation in XMLTokener.unescapeEntity()
2026-01-30 08:13:34 -06:00
Pratik Tiwari 7a8da886e7 Remove unnecessary conditions 2026-01-30 19:29:46 +05:30
OwenSanzas 0737e04f8a Add unit tests for JSONML ClassCastException fix
Added comprehensive test coverage for safe type casting:

Exception cases (should throw JSONException, not ClassCastException):
- Malformed XML causing type mismatch in toJSONArray()
- Type mismatch in toJSONObject()

Valid cases (should continue to work):
- Valid XML to JSONArray conversion
- Valid XML to JSONObject conversion

These tests verify the fix for issue #1034 where ClassCastException
was thrown when parse() returned unexpected types.
2026-01-28 10:07:34 +00:00