Skip to content

Commit

Permalink
fix(functions): schema fn should allow redundant escapes (#1787)
Browse files Browse the repository at this point in the history
Co-authored-by: Nauman <mnaumanali94@gmail.com>
  • Loading branch information
P0lip and mnaumanali94 committed Aug 31, 2021
1 parent b5c6a8f commit 5a29d44
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/functions/src/__tests__/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ describe('Core Functions / Schema', () => {
expect(await runSchema(2, { schema, dialect: 'auto' })).toStrictEqual(result);
});

it('allows redundant escapes', async () => {
let schema = {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'string',
pattern: '[\\-_]', // this one is good and would work with unicodeRegExp: true
};

expect(await runSchema(2, { schema })).toEqual([
{
message: 'Value type must be string',
path: [],
},
]);

schema = {
$schema: 'http://json-schema.org/draft-06/schema#',
type: 'string',
pattern: '[\\_-]', // the escape here is redundant
};

expect(await runSchema(2, { schema })).toEqual([
{
message: 'Value type must be string',
path: [],
},
]);
});

describe('validates falsy values such as', () => {
it('empty string', async () => {
const schema: JSONSchema = {
Expand Down
10 changes: 9 additions & 1 deletion packages/functions/src/schema/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ const logger = {
};

function createAjvInstance(Ajv: typeof AjvCore, allErrors: boolean): AjvCore {
const ajv = new Ajv({ allErrors, meta: true, messages: true, strict: false, allowUnionTypes: true, logger });
const ajv = new Ajv({
allErrors,
meta: true,
messages: true,
strict: false,
allowUnionTypes: true,
logger,
unicodeRegExp: false,
});
addFormats(ajv);
if (allErrors) {
ajvErrors(ajv);
Expand Down

0 comments on commit 5a29d44

Please sign in to comment.