Repository navigation
Conversation
…Path variable Port of dtq-dev PR 1556 (commit 612aa63).
There was a problem hiding this comment.
🟡 Changes recommended
Search-text bindings lack regression tests for apostrophes, injection-shaped input, and multi-level variable mapping, while the XPath resolver unnecessarily repeats lowercasing for each candidate node.
2 open issues
What changed in this PR
This PR hardens controlled-vocabulary lookups against XPath injection by binding search text and node IDs as variables rather than inserting them into expressions.
Changes:
- Adds variable binding for search, exact-match, and node-ID lookups.
- Adds regression tests for injection-shaped node IDs and valid hierarchy navigation.
- Extends the test vocabulary with a nested
pondnode.
| File | Description |
|---|---|
dspace-api/src/test/java/org/dspace/content/authority/DSpaceControlledVocabularyTest.java |
Adds node-ID regression coverage and strengthens the search assertion. |
dspace-api/src/test/data/dspaceFolder/config/controlled-vocabularies/farm.xml |
Adds pond beneath s40 for hierarchy tests. |
dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java |
Binds XPath variables and includes minor code and Javadoc cleanup. |
Review effort: Balanced
| String varName = variableName.getLocalPart(); | ||
| if (varName.startsWith("var")) { | ||
| int index = Integer.parseInt(varName.substring(3)); | ||
| return textHierarchy[index].toLowerCase(); |
Comment on lines
+205
to
+209
| xpath.setXPathVariableResolver(variableName -> { | ||
| String varName = variableName.getLocalPart(); | ||
| if (varName.startsWith("var")) { | ||
| int index = Integer.parseInt(varName.substring(3)); | ||
| return textHierarchy[index]; |
This branch has not been deployed
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.

References
Port of dtq-dev PR 1556 (commit 612aa63). dspace-customers issue 1083, finding V4.
Upstream commits ceab952 (DSpace#11075, label search) and aa419b9 (DSpace#11964, node id).
Upstream: DSpace#13386 (
dspace-9_x) and DSpace#13387 (dspace-8_x) port the same node id fix (open).Description
DSpaceControlledVocabularyput the node id and the search text from the request straight into XPath expressions, so a'could change the query. Both are now XPath variables.Instructions for Reviewers
getMatchesandgetBestMatchbind the search text, andgetChoice,getChoicesByParentandgetParentChoicebind the node id as XPath variables.testNodeIdIsNotEvaluatedAsXPath. The testfarm.xmlgets apondnode unders40.DSpaceControlledVocabularyTest. Locally on this branch (7.6.1):Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Checkstyle passes.Checklist