1531 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
Sean Leary 9926542da1 Merge pull request #1094 from labkey-jeckels/fb_share_parsed_keys_1091
Share repeated object keys within a parse (#1091)
2026-10-25 11:46:26 -05:00
labkey-jeckels 293bbf65d3 Share repeated object keys within a parse (#1091) 2026-10-20 09:54:00 -07:00
Sean Leary 69383f746d Merge pull request #1090 from JimmyLiuJia/fix/json-pointer-fragment-plus
Preserve plus signs in JSONPointer URI fragments
2026-10-15 07:50:28 -05:00
Sean Leary e5e97f87b1 Specify requirements for code changes and pull requests
Added requirements for code changes and pull requests to ensure backward compatibility and proper issue reporting.
2026-10-11 11:36:41 -05: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
Sean Leary babc520380 Merge pull request #1084 from zemiles/master
Fix reserved childNodes attribute check in JSONML
2026-10-05 20:14:31 -05: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
Sean Leary 18e8ef6e61 Merge pull request #1083 from DarkLight606/fix/1082
Fix a parsing error in JSONPointer.toURIFragment()
2026-09-30 08:09:17 -05: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
Sean Leary 4f822e0292 Merge pull request #1077 from Mahmoodifar/fix/parser-configuration-precedence
Apply explicit parser configuration to nested values
2026-09-20 21:44:30 -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
Sean Leary 8746735758 Merge pull request #1074 from XIAYM-gh/master
Fix strict mode failure when JSONTokener.next() and back() are called before parsing
2026-09-13 07:57:15 -05:00
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
Sean Leary 6c14048079 Merge pull request #1073 from stleary/pre-release-20260814
20260814 prep for next release
20260814
2026-08-14 11:09:30 -05:00
Sean Leary 34efda6423 pre-release-20260814 initial commit 2026-08-14 10:54:22 -05:00
Sean Leary 22ab2fb724 Update jar file link in README 2026-07-31 15:28:31 -05:00
Sean Leary 392a352901 Fix formatting of the latest release jar file link 2026-07-31 15:26:28 -05:00
Sean Leary b594a3229c Merge pull request #1070 from dong0713/fix/xml-unescape-whitespace-control-chars
Fix XML.unescape rejecting valid whitespace numeric character references
2026-07-29 07:50:07 -05: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 1795e8cf26 Merge pull request #1069 from stleary/pre-release-20260719
20260719 prep for next release
20260719
2026-07-19 14:04:18 -05: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 d24bc9e5d6 pre-release-20260719 initial commit 2026-07-19 12:51:08 -05:00
Sean Leary 80efb529d7 Merge pull request #1068 from stleary/max-number-length-config
Max number length config for BigInteger and BigDecimal
2026-07-19 12:43:09 -05:00
Sean Leary 9953b76050 max-number-length-config sonarqube fixes 2026-07-16 13:23:39 -05:00
Sean Leary a28328c706 Merge pull request #1067 from mechko/1063-biginteger-exponent-dos
#1063: bound BigDecimal→BigInteger expansion in objectToBigInteger (completes CVE-2026-59171 fix)
2026-07-16 12:31:17 -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