@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final String value = data.getInstance().getNode().textValue(); if (!RhinoHelper.regexIsValid(value)) report.error(newMsg(data, bundle, "err.format.invalidRegex") .putArgument("value", value)); } }
public Iterable<JsonPointer> selectSchemas(final String memberName) { final List<JsonPointer> list = Lists.newArrayList(); if (properties.contains(memberName)) list.add(PROPERTIES.append(memberName)); for (final String regex: patternProperties) if (RhinoHelper.regMatch(regex, memberName)) list.add(PATTERNPROPERTIES.append(regex)); if (!list.isEmpty()) return ImmutableList.copyOf(list); return hasAdditional ? ImmutableList.of(ADDITIONALPROPERTIES) : Collections.<JsonPointer>emptyList(); } }
@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 (!RhinoHelper.regexIsValid(s)) report.error(newMsg(tree, bundle, "common.patternProperties.member.notRegex") .putArgument("propertyName", s)); } }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { if (additionalOK) return; final JsonNode instance = data.getInstance().getNode(); final Set<String> fields = Sets.newHashSet(instance.fieldNames()); fields.removeAll(properties); final Set<String> tmp = Sets.newHashSet(); for (final String field: fields) for (final String regex: patternProperties) if (RhinoHelper.regMatch(regex, field)) tmp.add(field); fields.removeAll(tmp); if (fields.isEmpty()) return; /* * Display extra properties in order in the report */ final ArrayNode node = JacksonUtils.nodeFactory().arrayNode(); for (final String field: Ordering.natural().sortedCopy(fields)) node.add(field); report.error(newMsg(data, bundle, "err.common.additionalProperties.notAllowed") .putArgument("unwanted", node)); }
@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 (!RhinoHelper.regexIsValid(s)) report.error(newMsg(tree, bundle, "common.patternProperties.member.notRegex") .putArgument("propertyName", s)); } }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final String regex = data.getSchema().getNode().get(keyword) .textValue(); final String value = data.getInstance().getNode().textValue(); if (!RhinoHelper.regMatch(regex, value)) report.error(newMsg(data, bundle, "err.common.pattern.noMatch") .putArgument("regex", regex).putArgument("string", value)); }
@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 (!RhinoHelper.regexIsValid(value)) report.error(newMsg(tree, bundle, "common.invalidRegex") .putArgument("value", value)); } }
@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); } }
@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 (!RhinoHelper.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); }