/** * <p>Matches an input against a given regex, in the <b>real</b> sense * of matching, that is, the regex can match anywhere in the input. Java's * {@link java.util.regex} makes the unfortunate mistake to make people * believe that matching is done on the whole input... Which is not true. * </p> * * <p>Also note that the regex MUST have been validated at this point * (using {@link #regexIsValid(String)}).</p> * * @param regex the regex to use * @param input the input to match against (and again, see description) * @return true if the regex matches the input * @deprecated use {@link RegexECMA262Helper#regMatch(String, String)} */ @Deprecated public static boolean regMatch(final String regex, final String input) { return RegexECMA262Helper.regMatch(regex, input); } }
/** * Validate that a regex is correct * * @param regex the regex to validate * @return true if the regex is valid * @deprecated use {@link RegexECMA262Helper#regexIsValid(String)} */ @Deprecated public static boolean regexIsValid(final String regex) { return RegexECMA262Helper.regexIsValid(regex); }
/** * Validate that a regex is correct * * @param regex the regex to validate * @return true if the regex is valid */ public static boolean regexIsValid(final String regex) { if(PRIMARY_SCRIPT_ENGINE != null) { return invokeScriptEngine(REGEX_IS_VALID_FUNCTION_NAME, regex); } return invokeFallbackEngine(REGEX_IS_VALID, regex); }
@Override protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree) throws ProcessingException { /* * Check that the member names are regexes */ final Set<String> set = Sets.newHashSet(getNode(tree).fieldNames()); for (final String s: Ordering.natural().sortedCopy(set)) if (!RegexECMA262Helper.regexIsValid(s)) report.error(newMsg(tree, bundle, "common.patternProperties.member.notRegex") .putArgument("propertyName", s)); } }
@Test( dataProvider = "regexTestCases", invocationCount = 10, threadPoolSize = 4 ) public void regexMatchingIsDoneCorrectly(final String regex, final String input, final boolean valid) { assertEquals(RegexECMA262Helper.regMatch(regex, input), valid); assertEquals(RhinoHelper.regMatch(regex, input), valid); } }
/** * <p>Matches an input against a given regex, in the <b>real</b> sense * of matching, that is, the regex can match anywhere in the input. Java's * {@link java.util.regex} makes the unfortunate mistake to make people * believe that matching is done on the whole input... Which is not true. * </p> * * <p>Also note that the regex MUST have been validated at this point * (using {@link #regexIsValid(String)}).</p> * * @param regex the regex to use * @param input the input to match against (and again, see description) * @return true if the regex matches the input */ public static boolean regMatch(final String regex, final String input) { if(PRIMARY_SCRIPT_ENGINE != null) { return invokeScriptEngine(REG_MATCH_FUNCTION_NAME, regex, input); } return invokeFallbackEngine(REG_MATCH, regex, input); }
@Override protected void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final String value = getNode(tree).textValue(); if (!RegexECMA262Helper.regexIsValid(value)) report.error(newMsg(tree, bundle, "common.invalidRegex") .putArgument("value", value)); } }
@Test( dataProvider = "ecma262regexes", invocationCount = 10, threadPoolSize = 4 ) public void regexesAreCorrectlyAnalyzed(final String regex, final boolean valid) { assertEquals(RegexECMA262Helper.regexIsValid(regex), valid); assertEquals(RhinoHelper.regexIsValid(regex), valid); }