-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves improper anchoring of patternProperties (#783)
* Resolves improper anchoring of patternProperties Fixes #782 * Resolves improper anchoring of regular expressions in both Joni and JDK engines. Resolves #495 and #782 --------- Co-authored-by: Faron Dutton <[email protected]>
- Loading branch information
Showing
6 changed files
with
274 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,97 @@ | ||
|
||
### Legend | ||
|
||
Symbol | Meaning | | ||
:-----:|---------| | ||
🟢 | Fully implemented | ||
🟡 | Partially implemented | ||
🔴 | Not implemented | ||
🚫 | Not defined in Schema Version. | ||
| Symbol | Meaning | | ||
|:------:|:----------------------| | ||
| 🟢 | Fully implemented | | ||
| 🟡 | Partially implemented | | ||
| 🔴 | Not implemented | | ||
| 🚫 | Not defined | | ||
|
||
### Compatibility with JSON Schema versions | ||
|
||
Validation Keyword/Schema | Draft 4 | Draft 6 | Draft 7 | Draft 2019-09 | | ||
---------------- |:--------------:|:-------: |:-------: |:-------------:| | ||
$ref | 🟢 | 🟢 | 🟢 | 🟢 | ||
additionalProperties | 🟢 | 🟢 | 🟢 | 🟢 | ||
additionalItems | 🟢 | 🟢 | 🟢 | 🟢 | ||
allOf | 🟢 | 🟢 | 🟢 | 🟢 | ||
anyOf | 🟢 | 🟢 | 🟢 | 🟢 | ||
const | 🚫 | 🟢 | 🟢 | 🟢 | ||
contains | 🚫 | 🟢 | 🟢 | 🟢 | ||
contentEncoding | 🚫 | 🚫 | 🔴 | 🔴 | ||
contentMediaType | 🚫 | 🚫 | 🔴 | 🔴 | ||
dependencies | 🟢 | 🟢 |🟢 | 🟢 | ||
enum | 🟢 | 🟢 | 🟢 | 🟢 | ||
exclusiveMaximum (boolean) | 🟢 | 🚫 | 🚫 | 🚫 | ||
exclusiveMaximum (numeric) | 🚫 | 🟢 | 🟢 | 🟢 | ||
exclusiveMinimum (boolean) | 🟢 | 🚫 | 🚫 | 🚫 | ||
exclusiveMinimum (numeric) | 🚫 | 🟢 | 🟢 | 🟢 | ||
items | 🟢 | 🟢 | 🟢 | 🟢 | ||
maximum | 🟢 | 🟢 | 🟢 | 🟢 | ||
maxItems | 🟢 | 🟢 | 🟢 | 🟢 | ||
maxLength | 🟢 | 🟢 | 🟢 | 🟢 | ||
maxProperties | 🟢 | 🟢 | 🟢 | 🟢 | ||
minimum | 🟢 | 🟢 | 🟢 | 🟢 | ||
minItems | 🟢 | 🟢 | 🟢 | 🟢 | ||
minLength | 🟢 | 🟢 | 🟢 | 🟢 | ||
minProperties | 🟢 | 🟢 | 🟢 | 🟢 | ||
multipleOf | 🟢 | 🟢 | 🟢 | 🟢 | ||
not | 🟢 | 🟢 | 🟢 | 🟢 | ||
oneOf | 🟢 | 🟢 | 🟢 | 🟢 | ||
pattern | 🟢 | 🟢 | 🟢 | 🟢 | ||
patternProperties | 🟢 | 🟢 | 🟢 | 🟢 | ||
properties | 🟢 | 🟢 | 🟢 | 🟢 | ||
propertyNames | 🚫 | 🔴 | 🔴 | 🔴 | ||
required | 🟢 | 🟢 | 🟢 | 🟢 | ||
type | 🟢 | 🟢 | 🟢 | 🟢 | ||
uniqueItems | 🟢 | 🟢 | 🟢 | 🟢 | ||
| Keyword | Draft 4 | Draft 6 | Draft 7 | Draft 2019-09 | Draft 2020-12 | | ||
|:---------------------------|:-------:|:-------:|:-------:|:-------------:|:-------------:| | ||
| $anchor | 🚫 | 🚫 | 🚫 | 🔴 | 🔴 | | ||
| $dynamicAnchor | 🚫 | 🚫 | 🚫 | 🚫 | 🔴 | | ||
| $dynamicRef | 🚫 | 🚫 | 🚫 | 🚫 | 🔴 | | ||
| $id | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | | ||
| $recursiveAnchor | 🚫 | 🚫 | 🚫 | 🔴 | 🔴 | | ||
| $recursiveRef | 🚫 | 🚫 | 🚫 | 🔴 | 🔴 | | ||
| $ref | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | | ||
| $vocabulary | 🚫 | 🚫 | 🚫 | 🔴 | 🔴 | | ||
| additionalItems | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| additionalProperties | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| allOf | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| anyOf | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| const | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| contains | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| contentEncoding | 🚫 | 🚫 | 🔴 | 🔴 | 🔴 | | ||
| contentMediaType | 🚫 | 🚫 | 🔴 | 🔴 | 🔴 | | ||
| contentSchema | 🚫 | 🚫 | 🚫 | 🔴 | 🔴 | | ||
| definitions | 🟢 | 🟢 | 🟢 | 🚫 | 🚫 | | ||
| defs | 🚫 | 🚫 | 🚫 | 🟢 | 🟢 | | ||
| dependencies | 🟢 | 🟢 | 🟢 | 🚫 | 🚫 | | ||
| dependentRequired | 🚫 | 🚫 | 🚫 | 🟢 | 🟢 | | ||
| dependentSchemas | 🚫 | 🚫 | 🚫 | 🟢 | 🟢 | | ||
| enum | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| exclusiveMaximum (boolean) | 🟢 | 🚫 | 🚫 | 🚫 | 🚫 | | ||
| exclusiveMaximum (numeric) | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| exclusiveMinimum (boolean) | 🟢 | 🚫 | 🚫 | 🚫 | 🚫 | | ||
| exclusiveMinimum (numeric) | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| if-then-else | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
| items | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| maxContains | 🚫 | 🚫 | 🚫 | 🟢 | 🟢 | | ||
| minContains | 🚫 | 🚫 | 🚫 | 🟢 | 🟢 | | ||
| maximum | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| maxItems | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| maxLength | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| maxProperties | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| minimum | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| minItems | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| minLength | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| minProperties | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| multipleOf | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| not | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| oneOf | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| pattern | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| patternProperties | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| prefixItems | 🚫 | 🚫 | 🚫 | 🚫 | 🟢 | | ||
| properties | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| propertyNames | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| readOnly | 🚫 | 🚫 | 🔴 | 🔴 | 🔴 | | ||
| required | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| type | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| unevaluatedItems | 🚫 | 🚫 | 🚫 | 🟢 | 🟢 | | ||
| unevaluatedProperties | 🚫 | 🚫 | 🚫 | 🟢 | 🟢 | | ||
| uniqueItems | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| writeOnly | 🚫 | 🚫 | 🔴 | 🔴 | 🔴 | | ||
|
||
### Semantic Validation (Format) | ||
|
||
Format | Draft 4 | Draft 6 | Draft 7 | Draft 2019-09 | | ||
-------|---------|---------|---------|---------------| | ||
date |🚫 | 🚫 | 🟢 | 🟢 | ||
date-time | 🟢 | 🟢 | 🟢 | 🟢 | ||
duration | 🚫 | 🚫 | 🔴 | 🔴 | ||
email | 🟢 | 🟢 | 🟢 | 🟢 | ||
hostname | 🟢 | 🟢 | 🟢 | 🟢 | ||
idn-email | 🚫 | 🚫 | 🔴 | 🔴 | ||
idn-hostname | 🚫 | 🚫 | 🔴 | 🔴 | ||
ipv4 | 🟢 | 🟢 | 🟢 | 🟢 | ||
ipv6 | 🟢 | 🟢 | 🟢 | 🟢 | ||
iri | 🚫 | 🚫 | 🔴 | 🔴 | ||
iri-reference | 🚫 | 🚫 | 🔴 | 🔴 | ||
json-pointer | 🚫 | 🔴 | 🔴 | 🔴 | ||
relative-json-pointer | 🚫 | 🔴 | 🔴 | 🔴 | ||
regex | 🚫 | 🚫 | 🔴 | 🔴 | ||
time | 🚫 | 🚫 | 🟢 | 🟢 | ||
uri | 🟢 | 🟢 | 🟢 | 🟢 | ||
uri-reference | 🚫 | 🔴 | 🔴 | 🔴 | ||
uri-template | 🚫 | 🔴 | 🔴 | 🔴 | ||
uuid | 🚫 | 🚫 | 🟢 | 🟢 | ||
| Format | Draft 4 | Draft 6 | Draft 7 | Draft 2019-09 | Draft 2020-12 | | ||
|:----------------------|:-------:|:-------:|:-------:|:-------------:|:-------------:| | ||
| date | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
| date-time | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| duration | 🚫 | 🚫 | 🚫 | 🟢 | 🟢 | | ||
| email | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| hostname | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| idn-email | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
| idn-hostname | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
| ipv4 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| ipv6 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| iri | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
| iri-reference | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
| json-pointer | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| relative-json-pointer | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| regex | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
| time | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
| uri | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| uri-reference | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| uri-template | 🚫 | 🟢 | 🟢 | 🟢 | 🟢 | | ||
| uuid | 🚫 | 🚫 | 🟢 | 🟢 | 🟢 | | ||
|
||
### Footnotes | ||
1. Note that the validation are only optional for some of the keywords/formats. | ||
2. Refer to the corresponding JSON schema for more information on whether the keyword/format is optional or not. | ||
|
8 changes: 7 additions & 1 deletion
8
src/main/java/com/networknt/schema/regex/JDKRegularExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
package com.networknt.schema.regex; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
class JDKRegularExpression implements RegularExpression { | ||
private final Pattern pattern; | ||
private final boolean hasStartAnchor; | ||
private final boolean hasEndAnchor; | ||
|
||
JDKRegularExpression(String regex) { | ||
this.pattern = Pattern.compile(regex); | ||
this.hasStartAnchor = '^' == regex.charAt(0); | ||
this.hasEndAnchor = '$' == regex.charAt(regex.length() - 1); | ||
} | ||
|
||
@Override | ||
public boolean matches(String value) { | ||
return this.pattern.matcher(value).matches(); | ||
Matcher matcher = this.pattern.matcher(value); | ||
return matcher.find() && (!this.hasStartAnchor || 0 == matcher.start()) && (!this.hasEndAnchor || matcher.end() == value.length()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
[ | ||
{ | ||
"description": "issue495 using ECMA-262", | ||
"regex": "ecma-262", | ||
"schema": { | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"pattern": "^[a-z]{1,10}$", | ||
"unevaluatedProperties": false | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "an expected property name", | ||
"data": { "aaa": 3 }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "trailing newline", | ||
"data": { "aaa\n": 3 }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "embedded newline", | ||
"data": { "aaa\nbbb": 3 }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "leading newline", | ||
"data": { "\nbbb": 3 }, | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "issue495 using Java Pattern", | ||
"regex": "jdk", | ||
"schema": { | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"pattern": "^[a-z]{1,10}$", | ||
"unevaluatedProperties": false | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "an expected property name", | ||
"data": { "aaa": 3 }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "trailing newline", | ||
"data": { "aaa\n": 3 }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "embedded newline", | ||
"data": { "aaa\nbbb": 3 }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "leading newline", | ||
"data": { "\nbbb": 3 }, | ||
"valid": false | ||
} | ||
] | ||
} | ||
] |
Oops, something went wrong.