Skip to content

Commit

Permalink
supported regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivanshu-07 committed Feb 14, 2025
1 parent d833c07 commit 1bed851
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/config/src/utils/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export function sanitizeObject(obj) {
if (!obj || typeof obj !== 'object' || isArray(obj)) {
return obj;
}
if (obj instanceof RegExp) {
return obj;
}
const sanitized = {};
for (const key in obj) {
if (isSafeKey(key)) {
Expand Down
11 changes: 11 additions & 0 deletions packages/config/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ describe('PercyConfig', () => {
key: { key1: 123 }
});
});

it('does allow regex', () => {
// const overrides = JSON.parse('{"key":{"key1":/\d$/}}');
const overrides = {"key":{"key1":/\d$/}}

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

A space is required after '{'

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

Unnecessarily quoted property 'key' found

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

Missing space before value for key 'key'

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

A space is required after '{'

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

Unnecessarily quoted property 'key1' found

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

Missing space before value for key 'key1'

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

A space is required before '}'

Check failure on line 230 in packages/config/test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint

A space is required before '}'
const result = PercyConfig.getDefaults(overrides);
expect(result).toEqual({
version: 2,
test: { value: 'foo' },
key: { key1: /\d$/ }
});
});
});

describe('.validate()', () => {
Expand Down

0 comments on commit 1bed851

Please # to comment.