-
-
Notifications
You must be signed in to change notification settings - Fork 864
/
unicodeRegExp.spec.ts
67 lines (58 loc) · 1.9 KB
/
unicodeRegExp.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import _Ajv from "../ajv"
import chai from "../chai"
const should = chai.should()
describe("unicodeRegExp option", () => {
const unicodeChar = "\uD83D\uDC4D"
const unicodeSchema = {
type: "string",
pattern: `^[${unicodeChar}]$`,
}
const schemaWithEscape = {
type: "string",
pattern: "^[\\:]$",
}
const patternPropertiesSchema = {
type: "object",
patternProperties: {
"^\\:.*$": {type: "number"},
},
additionalProperties: false,
}
describe("= true (default)", () => {
const ajv = new _Ajv()
it("should fail schema compilation if used invalid (unnecessary) escape sequence for pattern", () => {
should.throw(() => {
ajv.compile(schemaWithEscape)
}, /Invalid escape/)
})
it("should fail schema compilation if used invalid (unnecessary) escape sequence for patternProperties", () => {
should.throw(() => {
ajv.compile(patternPropertiesSchema)
}, /Invalid escape/)
})
it("should validate unicode character", () => {
const validate = ajv.compile(unicodeSchema)
validate(unicodeChar).should.equal(true)
})
})
describe("= false", () => {
const ajv = new _Ajv({unicodeRegExp: false})
it("should pass schema compilation if used unnecessary escape sequence for pattern", () => {
should.not.throw(() => {
const validate = ajv.compile(schemaWithEscape)
validate(":").should.equal(true)
})
})
it("should pass schema compilation if used unnecessary escape sequence for patternProperties", () => {
should.not.throw(() => {
const validate = ajv.compile(patternPropertiesSchema)
validate({":test": 1}).should.equal(true)
validate({test: 1}).should.equal(false)
})
})
it("should not validate unicode character", () => {
const validate = ajv.compile(unicodeSchema)
validate(unicodeChar).should.equal(false)
})
})
})