diff --git a/NOTICE b/NOTICE
index 2fe21eeead1..43c4b92efb0 100644
--- a/NOTICE
+++ b/NOTICE
@@ -14,6 +14,10 @@ This product also includes the following third-party components:
Downloaded from: https://lunrjs.com/
License: MIT
+* Saxon-HE
+ Downloaded from: https://www.saxonica.com/
+ License: Mozilla Public License 2.0
+
* search-ui
Downloaded from: https://gitlab.com/antora/antora-lunr-extension
License: Mozilla Public License 2.0
diff --git a/kie-dmn/kie-dmn-feel/pom.xml b/kie-dmn/kie-dmn-feel/pom.xml
index 51fbef420b7..545d181c628 100644
--- a/kie-dmn/kie-dmn-feel/pom.xml
+++ b/kie-dmn/kie-dmn-feel/pom.xml
@@ -38,8 +38,19 @@
org.kie.dmn.feel
2
true
+ 12.5
+
+
+
+ net.sf.saxon
+ Saxon-HE
+ ${version.net.sf.saxon.Saxon-HE}
+
+
+
+
@@ -52,6 +63,10 @@
+
+ net.sf.saxon
+ Saxon-HE
+
org.antlr
antlr4-runtime
diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MatchesFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MatchesFunction.java
index 79ff2a01368..2acb38ad269 100644
--- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MatchesFunction.java
+++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MatchesFunction.java
@@ -18,15 +18,9 @@
*/
package org.kie.dmn.feel.runtime.functions;
-import java.security.InvalidParameterException;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-import java.util.stream.Collectors;
-
import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
+import org.kie.dmn.feel.util.XQueryImplUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,58 +38,23 @@ public FEELFnResult invoke(@ParameterName("input") String input, @Param
}
public FEELFnResult invoke(@ParameterName("input") String input, @ParameterName("pattern") String pattern, @ParameterName("flags") String flags) {
- try {
- return matchFunctionWithFlags(input,pattern,flags);
- } catch ( PatternSyntaxException t ) {
- return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "pattern", "is invalid and can not be compiled", t ) );
- } catch (InvalidParameterException t ) {
- return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, t.getMessage(), "cannot be null", t ) );
- } catch (IllegalArgumentException t ) {
- return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "flags", "contains unknown flags", t ) );
- } catch (Throwable t) {
- return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "pattern", "is invalid and can not be compiled", t ) );
- }
- }
-
- static FEELFnResult matchFunctionWithFlags(String input, String pattern, String flags) {
log.debug("Input: {} , Pattern: {}, Flags: {}", input, pattern, flags);
+
if ( input == null ) {
- throw new InvalidParameterException("input");
+ return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "input", "cannot be null" ) );
}
if ( pattern == null ) {
- throw new InvalidParameterException("pattern");
+ return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "pattern", "cannot be null" ) );
}
- final String flagsString;
- if (flags != null && !flags.isEmpty()) {
- checkFlags(flags);
- if(!flags.contains("U")){
- flags += "U";
- }
- flagsString = String.format("(?%s)", flags);
- } else {
- flagsString = "";
- }
- log.debug("flagsString: {}", flagsString);
- String stringToBeMatched = flagsString + pattern;
- log.debug("stringToBeMatched: {}", stringToBeMatched);
- Pattern p=Pattern.compile(stringToBeMatched);
- Matcher m = p.matcher( input );
- boolean matchFound=m.find();
- log.debug("matchFound: {}", matchFound);
- return FEELFnResult.ofResult(matchFound);
- }
- static void checkFlags(String flags) {
- Set allowedChars = Set.of('s','i','x','m');
- boolean isValidFlag= flags.chars()
- .mapToObj(c -> (char) c)
- .allMatch(allowedChars::contains)
- && flags.chars()
- .mapToObj(c -> (char) c)
- .collect(Collectors.toSet())
- .size() == flags.length();
- if(!isValidFlag){
- throw new IllegalArgumentException("Not a valid flag parameter " +flags);
- }
+ try {
+ return FEELFnResult.ofResult(XQueryImplUtil.executeMatchesFunction(input, pattern, flags));
+ } catch (Exception e) {
+ String errorMessage = String.format("Provided parameters lead to an error. Input: '%s', Pattern: '%s', Flags: '%s'. ", input, pattern, flags);
+ if (e.getMessage() != null && !e.getMessage().isEmpty()) {
+ errorMessage += e.getMessage();
+ }
+ return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, errorMessage, e));
+ }
}
}
diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReplaceFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReplaceFunction.java
index 723efcbdd36..a7ae497870a 100644
--- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReplaceFunction.java
+++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReplaceFunction.java
@@ -20,6 +20,7 @@
import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
+import org.kie.dmn.feel.util.XQueryImplUtil;
public class ReplaceFunction
extends BaseFEELFunction {
@@ -30,12 +31,12 @@ private ReplaceFunction() {
super( "replace" );
}
- public FEELFnResult