File tree Expand file tree Collapse file tree 4 files changed +31
-4
lines changed
main/java/com/networknt/schema/format
test/java/com/networknt/schema/format Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ protected boolean validate(URI uri) {
13
13
// Java URI accepts non ASCII characters and this is not a valid in RFC3986
14
14
result = uri .toString ().codePoints ().allMatch (ch -> ch < 0x7F );
15
15
if (result ) {
16
- String query = uri .getQuery ();
16
+ String query = uri .getRawQuery ();
17
17
if (query != null ) {
18
18
// [ and ] must be percent encoded
19
19
if (query .indexOf ('[' ) != -1 || query .indexOf (']' ) != -1 ) {
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ protected boolean validate(URI uri) {
11
11
// Java URI accepts non ASCII characters and this is not a valid in RFC3986
12
12
boolean result = uri .toString ().codePoints ().allMatch (ch -> ch < 0x7F );
13
13
if (result ) {
14
- String query = uri .getQuery ();
14
+ String query = uri .getRawQuery ();
15
15
if (query != null ) {
16
16
// [ and ] must be percent encoded
17
17
if (query .indexOf ('[' ) != -1 || query .indexOf (']' ) != -1 ) {
Original file line number Diff line number Diff line change @@ -56,7 +56,21 @@ void queryWithBracketsShouldFail() {
56
56
InputFormat .JSON );
57
57
assertFalse (messages .isEmpty ());
58
58
}
59
-
59
+
60
+ @ Test
61
+ void queryWithEncodedBracketsShouldPass () {
62
+ String schemaData = "{\r \n "
63
+ + " \" format\" : \" uri\" \r \n "
64
+ + "}" ;
65
+
66
+ SchemaValidatorsConfig config = new SchemaValidatorsConfig ();
67
+ config .setFormatAssertionsEnabled (true );
68
+ JsonSchema schema = JsonSchemaFactory .getInstance (VersionFlag .V202012 ).getSchema (schemaData , config );
69
+ Set <ValidationMessage > messages = schema .validate ("\" https://test.com/assets/product.pdf?filter%5Btest%5D=1\" " ,
70
+ InputFormat .JSON );
71
+ assertTrue (messages .isEmpty ());
72
+ }
73
+
60
74
@ Test
61
75
void iriShouldFail () {
62
76
String schemaData = "{\r \n "
@@ -70,5 +84,4 @@ void iriShouldFail() {
70
84
InputFormat .JSON );
71
85
assertFalse (messages .isEmpty ());
72
86
}
73
-
74
87
}
Original file line number Diff line number Diff line change @@ -57,6 +57,20 @@ void queryWithBracketsShouldFail() {
57
57
assertFalse (messages .isEmpty ());
58
58
}
59
59
60
+ @ Test
61
+ void queryWithEncodedBracketsShouldPass () {
62
+ String schemaData = "{\r \n "
63
+ + " \" format\" : \" uri-reference\" \r \n "
64
+ + "}" ;
65
+
66
+ SchemaValidatorsConfig config = new SchemaValidatorsConfig ();
67
+ config .setFormatAssertionsEnabled (true );
68
+ JsonSchema schema = JsonSchemaFactory .getInstance (VersionFlag .V202012 ).getSchema (schemaData , config );
69
+ Set <ValidationMessage > messages = schema .validate ("\" https://test.com/assets/product.pdf?filter%5Btest%5D=1\" " ,
70
+ InputFormat .JSON );
71
+ assertTrue (messages .isEmpty ());
72
+ }
73
+
60
74
@ Test
61
75
void iriShouldFail () {
62
76
String schemaData = "{\r \n "
You can’t perform that action at this time.
0 commit comments