bncriju commented on code in PR #6320:
URL:
https://github.com/apache/incubator-kie-drools/pull/6320#discussion_r2054460147
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/XQueryImplUtil.java:
##########
@@ -26,17 +26,25 @@
import net.sf.saxon.s9api.XQueryExecutable;
import net.sf.saxon.s9api.SaxonApiException;
+import java.util.regex.Pattern;
+
public class XQueryImplUtil {
+ static Pattern XML_CHARACTER_REFERENCES_PATTERN =
Pattern.compile("['\"&<>]");
Review Comment:
Could be private static final since it's not accessed externally and is
constant.
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/XQueryImplUtil.java:
##########
@@ -26,17 +26,25 @@
import net.sf.saxon.s9api.XQueryExecutable;
import net.sf.saxon.s9api.SaxonApiException;
+import java.util.regex.Pattern;
+
public class XQueryImplUtil {
+ static Pattern XML_CHARACTER_REFERENCES_PATTERN =
Pattern.compile("['\"&<>]");
+
+ private XQueryImplUtil() {
+ // Util class with static methods only.
+ }
+
public static Boolean executeMatchesFunction(String input, String pattern,
String flags) {
flags = flags == null ? "" : flags;
- String xQueryExpression = String.format("matches('%s', '%s', '%s')",
input, pattern, flags);
+ String xQueryExpression = String.format("matches('%s', '%s', '%s')",
sanitizeXmlCharacterReferences(input), sanitizeXmlCharacterReferences(pattern),
flags);
Review Comment:
renaming method 'sanitizeXmlCharacterReferences' to precise method name
'escapeXmlSpecialCharactersForXQuery' would help
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java:
##########
@@ -98,6 +98,20 @@ private static Object[][]
invokeWithoutFlagsPatternTestData() {
};
}
+ @ParameterizedTest
+ @MethodSource("invokeWithXmlCharacterReferencesData")
+ void invokeWithXmlCharacterReferencesTest(String input, String pattern,
String replacement, String expectedResult) {
+ FunctionTestUtil.assertResult(replaceFunction.invoke(input, pattern,
replacement), expectedResult);
+ }
+
+ private static Object[][] invokeWithXmlCharacterReferencesData() {
+ return new Object[][] {
+ { "abc&123", "abc", "123", "123&123" },
+ { "abc'123", "abc'", "123", "123123" },
+ { "abc\"123", "abc\"", "123<>", "123<>123" }
+ };
+ }
+
Review Comment:
Adding a test that verifies the raw XQuery expression string would be fine,
to ensure the escaping looks exactly as expected in the generated string eg:
'<&>' as input and pattern with no flag mentioned.
--
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]