Skip to content

Commit

Permalink
fix: Tighten regexp for JSON !!bool (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
vra5107 authored Nov 14, 2024
1 parent 2e85b91 commit 108f699
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/schema/json/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const jsonScalars: ScalarTag[] = [
identify: value => typeof value === 'boolean',
default: true,
tag: 'tag:yaml.org,2002:bool',
test: /^true|false$/,
test: /^true$|^false$/,
resolve: str => str === 'true',
stringify: stringifyJSON
},
Expand Down
20 changes: 20 additions & 0 deletions tests/doc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,26 @@ describe('json schema', () => {
)
})

test('!!bool: js-regex-missing-regexp-anchor', () => {
const src = `"canonical": truea
"answer": ffalse
"logical": Truea
"option": TruEp`

const doc = parseDocument(src, { schema: 'json' })
expect(doc.toJS()).toMatchObject({
canonical: 'truea',
answer: 'ffalse',
logical: 'Truea',
option: 'TruEp'
})
expect(doc.errors).toHaveLength(4)
doc.errors = []
expect(String(doc)).toBe(
'"canonical": "truea"\n"answer": "ffalse"\n"logical": "Truea"\n"option": "TruEp"\n'
)
})

test('!!float', () => {
const src = `"canonical": 6.8523015e+5
"fixed": 685230.15
Expand Down

0 comments on commit 108f699

Please sign in to comment.