-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: escape single quote when building error message for required pro…
…perty (#716) * Escape single quote in required property * Escape single quote in case the required property is missing in the list of properties * trigger ci * Add tests for double quote in property name --------- Co-authored-by: Gürgün Dayıoğlu <[email protected]>
- Loading branch information
1 parent
7aeac5e
commit ed8ed70
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict' | ||
|
||
const test = require('tap').test | ||
const build = require('..') | ||
|
||
test('required property containing single quote, contains property', (t) => { | ||
t.plan(1) | ||
|
||
const stringify = build({ | ||
type: 'object', | ||
properties: { | ||
'\'': { type: 'string' } | ||
}, | ||
required: [ | ||
'\'' | ||
] | ||
}) | ||
|
||
t.throws(() => stringify({}), new Error('"\'" is required!')) | ||
}) | ||
|
||
test('required property containing double quote, contains property', (t) => { | ||
t.plan(1) | ||
|
||
const stringify = build({ | ||
type: 'object', | ||
properties: { | ||
'"': { type: 'string' } | ||
}, | ||
required: [ | ||
'"' | ||
] | ||
}) | ||
|
||
t.throws(() => stringify({}), new Error('""" is required!')) | ||
}) | ||
|
||
test('required property containing single quote, does not contain property', (t) => { | ||
t.plan(1) | ||
|
||
const stringify = build({ | ||
type: 'object', | ||
properties: { | ||
a: { type: 'string' } | ||
}, | ||
required: [ | ||
'\'' | ||
] | ||
}) | ||
|
||
t.throws(() => stringify({}), new Error('"\'" is required!')) | ||
}) | ||
|
||
test('required property containing double quote, does not contain property', (t) => { | ||
t.plan(1) | ||
|
||
const stringify = build({ | ||
type: 'object', | ||
properties: { | ||
a: { type: 'string' } | ||
}, | ||
required: [ | ||
'"' | ||
] | ||
}) | ||
|
||
t.throws(() => stringify({}), new Error('""" is required!')) | ||
}) |