gitgabrio commented on code in PR #6871:
URL: https://github.com/apache/incubator-kie/pull/6871#discussion_r3734408429
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/XQueryImplUtil.java:
##########
@@ -66,22 +71,38 @@ static <T> T evaluateXQueryExpression(String expression,
Class<T> expectedTypeRe
} catch (SaxonApiException e) {
throw new IllegalArgumentException(e);
}
- }
+ }
/**
- * It replaces all the XML Character References (&, ", ', <, >) in a given
input string with their "escaping" characters.
- * This is required to run XPath functions containing XML Character
References.
- * @param input A string input representing one of the parameter of
managed functions
- * @return A sanitized string
+ * Escapes XML special characters ({@code & " ' < >}) so the value is safe
to embed
+ * as an XPath string literal. Returns {@code null} unchanged; returns the
original
+ * reference if no escaping is needed.
*/
static String escapeXmlCharactersReferencesForXPath(String input) {
- if (input != null &&
XML_CHARACTER_REFERENCES_PATTERN.matcher(input).find()) {
- input = input.contains("&") ? input.replace("&", "&") : input;
- input = input.contains("\"") ? input.replace("\"", """) :
input;
- input = input.contains("'") ? input.replace("'", "'") :
input;
- input = input.contains("<") ? input.replace("<", "<") : input;
- input = input.contains(">") ? input.replace(">", ">") : input;
+ if (input == null) {
+ return null;
+ }
+ StringBuilder sb = null;
Review Comment:
HI @yesamer
IIUC the logic, I think it would be possible to avoid the usage of `null`
semantic; i.e.
1. instantiate directly `sb`
2. here ->
`return sb != null ? sb.toString() : input;`
replace with
`return sb.isEmpty() ? input : sb.toString();`
I think it would a bit clearer (and less code/if): wdyt ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]