[bugfix] fn:xml-to-json: enforce F&O 3.1 §17.4.2 structural validation (+10 XQTS HEAD)#6350
Open
joewiz wants to merge 3 commits into
Open
Conversation
Adds the per-element-type validation required by F&O 3.1 §17.4.2 (XML Representation of JSON) and §17.5.4 (fn:xml-to-json): - Reject non-whitespace text node children of <map>/<array> elements (whitespace, comments and PIs are still ignored per spec). - Reject element children of leaf-type elements (<string>, <number>, <boolean>, <null>). - Reject no-namespace attributes other than 'key', 'escaped-key', 'escaped'; reject any attribute in the xpath-functions namespace (the schema's anyAttribute namespace="##other"). - Require 'escaped' and 'escaped-key' to hold a valid xs:boolean value. - Reject element names outside the six allowed local names at start-tag rather than only at end-tag. Per W3C bug 29917 / qt3tests xml-to-json-065, 'escaped' is tolerated on non-string elements (treated as a no-op); only the lexical value is enforced. Foreign-namespace attributes remain ignored, matching the schema rule. Closes the over-permissive-validation sub-cluster of fn-xml-to-json FOJS0006 failures identified in the 2026-05-10 triage report (predecessor PR eXist-db#6342 closed the walk-from-doc-root sub-cluster). XQTS HEAD fn-xml-to-json: +10 newly passing, 0 regressions on xml-to-json-{033, 040, 042, 043, 044, 062, 063, 069, 081, 082}. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
line-o
reviewed
May 11, 2026
| } | ||
|
|
||
| /** | ||
| * Validate the current START_ELEMENT against the F&O 3.1 §17.4.2 / §17.5.4 structural rules |
line-o
reviewed
May 11, 2026
| } | ||
|
|
||
| /** | ||
| * Reject non-whitespace text node children of {@code map} and {@code array} per F&O 3.1 §17.4.2. |
line-o
reviewed
May 11, 2026
| } | ||
|
|
||
| /** | ||
| * Validate that the attributes on the current element conform to F&O 3.1 §17.4.2 (the schema for JSON). |
Addresses line-o's review comments on PR eXist-db#6350 (lines 267, 288, 329). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
[This response was co-authored with Claude Code. -Joe] Fixed in |
reinhapa
requested changes
May 11, 2026
Addresses reinhapa's review on PR eXist-db#6350. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
[This response was co-authored with Claude Code. -Joe] Done in |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds per-element-type structural validation to
fn:xml-to-jsonas required by F&O 3.1 §17.4.2 (XML Representation of JSON) and §17.5.4. Before this change, develop silently accepted inputs that violate the spec's structural rules and produced a JSON result rather than raisingFOJS0006.This is a follow-up to #6342 (which closed the walk-from-doc-root sub-cluster of
fn-xml-to-jsonHEAD failures). It closes the over-permissive-validation sub-cluster identified in the 2026-05-10 triage of the FOJS0006 cluster.What changed
exist-core/src/main/java/org/exist/xquery/functions/fn/FunXmlToJson.java:<map>and<array>elements (whitespace, comments, and processing instructions are still ignored per spec).<string>,<number>,<boolean>,<null>).key,escaped-key, andescaped; reject any attribute in thehttp://www.w3.org/2005/xpath-functionsnamespace (the schema'sanyAttribute namespace=\"##other\").escapedandescaped-keyattribute values to be lexically validxs:boolean(true/false/1/0).map,array,string,number,boolean,null) at start-tag rather than only at end-tag.Per W3C bug 29917 / qt3tests
xml-to-json-065, theescapedattribute is tolerated on non-string elements (treated as a no-op); only the lexical value is enforced.Foreign-namespace attributes remain ignored, matching the schema's
anyAttribute namespace=\"##other\"rule on every element type.exist-core/src/test/xquery/xquery3/xml-to-json.xql: adds 14 XQSuite regression tests covering each new validation path plus the whitespace-allowed and foreign-namespace-attribute-ignored cases.Spec references
F&O 3.1 §17.4.2:
F&O 3.1 §17.5.4 Error Conditions:
F&O 3.1 Appendix C.2 Schema —
stringTypedeclares theescapedattribute;nullType,booleanType,numberType,arrayType,mapTypeeach declare only<xs:anyAttribute processContents=\"skip\" namespace=\"##other\"/>.XQTS HEAD delta
fn-xml-to-jsontest set:xml-to-json-{033, 040, 042, 043, 044, 062, 063, 069, 081, 082}(10)<map>/<array>yek)xs:booleanvalue forescaped-keyxs:booleanvalue forescaped<string><boolean><null>Baseline: develop @ a3865db (2026-05-11 XQ 3.1 HEAD canonical baseline).
Test plan
mvn test -pl exist-core -Dtest=xquery.xquery3.XQuery3Tests— 1025 pass (includes 14 new regression cases)fn-xml-to-jsonre-run shows +10 newly passing, 0 regressions vs develop baselinevalidateStartElementandvalidateTextInContexthelpers; no new findings (only pre-existingUnusedLocalVariableat line 73 andSimplifyBooleanExpressionsat line 207).🤖 Generated with Claude Code