xref: /aosp_15_r20/external/json-schema-validator/doc/ecma-262.md (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1For the pattern validator, we now have two options for regex in the library. The default one is `java.util.regex`; however, you can use the ECMA-262 standard library `org.jruby.joni` by configuration.
2
3As we know, the JSON schema is designed based on the Javascript language and its regex. The Java internal implementation has some differences which don't comply with the standard. For most users, these edge cases are not the issue as they are not using them anyway. Even when they are using it, they are expecting the Java regex result as the application is built on the Java platform. For users who want to ensure that they are using 100% standard patter validator, we have provided an option to override the default regex library with `org.jruby.joni` that is complying with the ECMA-262 standard.
4
5### Which one to choose?
6
7If you want a faster regex lib and don't care about the slight difference between Java and Javascript regex, then you don't need to do anything. The default regex lib is the `java.util.regex`.
8
9If you want to ensure full compliance, use the `org.jruby.joni`. It is 1.5 times slower then `java.util.regex`. Depending on your use case, it might not be an issue.
10
11### How to switch?
12
13Here is the test case that shows how to pass a config object to use the ECMA-262 library.
14
15```java
16@Test(expected = JsonSchemaException.class)
17public void testInvalidPatternPropertiesValidatorECMA262() throws Exception {
18    SchemaValidatorsConfig config = new SchemaValidatorsConfig();
19    config.setEcma262Validator(true);
20    JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
21    JsonSchema schema = factory.getSchema("{\"patternProperties\":6}", config);
22
23    JsonNode node = getJsonNodeFromStringContent("");
24    Set<ValidationMessage> errors = schema.validate(node);
25    Assert.assertEquals(errors.size(), 0);
26}
27```
28
29
30