|
25 | 25 | import java.util.HashSet; |
26 | 26 | import java.util.Locale; |
27 | 27 | import java.util.Map; |
28 | | -import java.util.regex.Pattern; |
29 | 28 |
|
30 | 29 | import org.apache.commons.lang3.StringUtils; |
31 | 30 | import org.apache.commons.logging.Log; |
|
36 | 35 | import org.htmlunit.ScriptResult; |
37 | 36 | import org.htmlunit.SgmlPage; |
38 | 37 | import org.htmlunit.WebClient; |
| 38 | +import org.htmlunit.corejs.javascript.Context; |
| 39 | +import org.htmlunit.corejs.javascript.regexp.RegExpEngineAccess; |
39 | 40 | import org.htmlunit.javascript.AbstractJavaScriptEngine; |
| 41 | +import org.htmlunit.javascript.HtmlUnitContextFactory; |
40 | 42 | import org.htmlunit.javascript.host.event.Event; |
41 | 43 | import org.htmlunit.javascript.host.event.MouseEvent; |
42 | 44 | import org.htmlunit.javascript.host.html.HTMLInputElement; |
43 | | -import org.htmlunit.javascript.regexp.RegExpJsToJavaConverter; |
44 | 45 | import org.htmlunit.util.NameValuePair; |
45 | 46 | import org.xml.sax.helpers.AttributesImpl; |
46 | 47 |
|
@@ -1011,10 +1012,12 @@ private boolean isPatternValid() { |
1011 | 1012 | return true; |
1012 | 1013 | } |
1013 | 1014 |
|
1014 | | - final RegExpJsToJavaConverter converter = new RegExpJsToJavaConverter(); |
1015 | | - final String javaPattern = converter.convert(pattern); |
1016 | | - try { |
1017 | | - return Pattern.matches(javaPattern, value); |
| 1015 | + try (Context cx = HtmlUnitContextFactory.getGlobal().enterContext()) { |
| 1016 | + RegExpEngineAccess.compile(cx, pattern, ""); |
| 1017 | + final RegExpEngineAccess.CompiledRegExp compiled |
| 1018 | + = RegExpEngineAccess.compile(cx, "^(?:" + pattern + ")$", ""); |
| 1019 | + |
| 1020 | + return RegExpEngineAccess.matches(cx, value, compiled); |
1018 | 1021 | } |
1019 | 1022 | catch (final Exception ignored) { |
1020 | 1023 | // ignore if regex invalid |
|
0 commit comments