Skip to content

escape ampersand entity prefixes in pointer paths - #292

Open
SABITHSAHEB wants to merge 1 commit into
apache:masterfrom
SABITHSAHEB:pointer-path-entity-escape
Open

SABITHSAHEB wants to merge 1 commit into
apache:masterfrom
SABITHSAHEB:pointer-path-entity-escape

Conversation

@SABITHSAHEB

Copy link
Copy Markdown
  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? Claude Code helped analyze the code and draft the change; it was reviewed and the build and tests were run before submission.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.
  1. NodePointer.escape writes ' and " as '/" but leaves & alone, so a dynamic property name containing the literal text ' yields the same asPath() as a name containing a real quote: a map with the keys Key'1 and Key'1 prints /map[@name='Key'1'] for both entries.
  2. Re-evaluating such a stored path with getValue, setValue or removePath then resolves to the wrong entry, so a name chosen to contain an entity sequence silently aliases a sibling entry's pointer path.
  3. escape now also emits & for an ampersand that starts an ', " or & sequence, and the parser's unescape (XPath.jj and the checked-in XPathParser.java) decodes & in a single left-to-right pass, so escaped output decodes to exactly the original name.

A lone & still needs no escaping and & only decodes where it appears literally, so existing stored paths and hand-written literals like 'Tom & Jerry' parse as before; the only changed input is a literal containing the exact sequence &, which previously could not be produced by asPath() at all. The new test in DynamicPropertiesModelTest fails before the change and passes after.

A dynamic property name containing the literal text ' produced the same asPath() as a name containing a real quote, so re-evaluating the stored path resolved to the wrong entry. escape() now emits & for an ampersand that starts an entity sequence and the parser's unescape() decodes it in a single pass. Lone ampersands are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant