Skip to content

Commit

Permalink
feat: add unicode flag to regular expressions, passes ecmascript-rege…
Browse files Browse the repository at this point in the history
…x and non-bmp-regex tests
  • Loading branch information
epoberezkin committed Sep 11, 2020
1 parent 8daaf7d commit 912c3f4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/vocabularies/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export function callValidateCode(
export function usePattern(gen: CodeGen, pattern: string): Name {
return gen.scopeValue("pattern", {
key: pattern,
ref: new RegExp(pattern),
code: _`new RegExp(${pattern})`,
ref: new RegExp(pattern, "u"),
code: _`new RegExp(${pattern}, "u")`,
})
}

Expand Down
3 changes: 1 addition & 2 deletions lib/vocabularies/validation/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const def: CodeKeywordDefinition = {
$data: true,
code(cxt: KeywordCxt) {
const {gen, data, $data, schema, schemaCode} = cxt
// const bdt = bad$DataType(schemaCode, <string>def.schemaType, $data)
const regExp = $data ? _`(new RegExp(${schemaCode}))` : usePattern(gen, schema) // TODO regexp should be wrapped in try/catch
const regExp = $data ? _`(new RegExp(${schemaCode}, "u"))` : usePattern(gen, schema) // TODO regexp should be wrapped in try/catch
cxt.fail$data(_`!${regExp}.test(${data})`)
},
error: {
Expand Down
2 changes: 0 additions & 2 deletions spec/json-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const remoteRefs = {
}

const SKIP6 = [
"optional/ecmascript-regex", // TODO only format needs to be skipped, too much is skipped here
"optional/non-bmp-regex",
"format",
"optional/format/date",
"optional/format/date-time",
Expand Down

0 comments on commit 912c3f4

Please sign in to comment.