Skip to content

Commit 2a28f87

Browse files
authored
Allow apostrophe in uri-template literal (#1275)
The uri-template format regex listed ' in its excluded character set, so "a'b" was reported invalid. An apostrophe in a literal is valid; remove it from the exclusion set.
1 parent f8c7659 commit 2a28f87

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/java/com/networknt/schema/format/Formats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static PatternFormat pattern(String name, String regex) {
4444
formats.add(new IPv6Format());
4545
formats.add(pattern("json-pointer", "^(/([^/#~]|[~](?=[01]))*)*$", "format.json-pointer"));
4646
formats.add(pattern("relative-json-pointer", "^(0|([1-9]\\d*))(#|(/([^/#~]|[~](?=[01]))*)*)$", "format.relative-json-pointer"));
47-
formats.add(pattern("uri-template", "^([^\\p{Cntrl}\"'%<>\\^`\\{|\\}]|%\\p{XDigit}{2}|\\{[+#./;?&=,!@|]?((\\w|%\\p{XDigit}{2})(\\.?(\\w|%\\p{XDigit}{2}))*(:[1-9]\\d{0,3}|\\*)?)(,((\\w|%\\p{XDigit}{2})(\\.?(\\w|%\\p{XDigit}{2}))*(:[1-9]\\d{0,3}|\\*)?))*\\})*$", "format.uri-template"));
47+
formats.add(pattern("uri-template", "^([^\\p{Cntrl}\"%<>\\^`\\{|\\}]|%\\p{XDigit}{2}|\\{[+#./;?&=,!@|]?((\\w|%\\p{XDigit}{2})(\\.?(\\w|%\\p{XDigit}{2}))*(:[1-9]\\d{0,3}|\\*)?)(,((\\w|%\\p{XDigit}{2})(\\.?(\\w|%\\p{XDigit}{2}))*(:[1-9]\\d{0,3}|\\*)?))*\\})*$", "format.uri-template"));
4848
formats.add(pattern("uuid", "^\\p{XDigit}{8}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{12}$", "format.uuid"));
4949
formats.add(new DateFormat());
5050
formats.add(new DateTimeFormat());

src/test/java/com/networknt/schema/FormatValidatorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,16 @@ void draft7DisableFormat() {
220220
});
221221
assertEquals(0, messages.size());
222222
}
223+
224+
@Test
225+
void uriTemplateAllowsApostropheInLiteral() {
226+
String schemaData = "{\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"format\":\"uri-template\"}";
227+
Schema schema = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12).getSchema(schemaData);
228+
// An apostrophe in a literal is valid.
229+
assertTrue(schema.validate("\"a'b\"", InputFormat.JSON,
230+
ec -> ec.executionConfig(c -> c.formatAssertionsEnabled(true))).isEmpty());
231+
// Expression syntax still validates.
232+
assertTrue(schema.validate("\"http://x/{y}\"", InputFormat.JSON,
233+
ec -> ec.executionConfig(c -> c.formatAssertionsEnabled(true))).isEmpty());
234+
}
223235
}

0 commit comments

Comments
 (0)