Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ export class SimpleHelpersModule extends SimpleModuleBase {

if (pattern instanceof RegExp) {
isCaseInsensitive = pattern.flags.includes('i');
pattern = pattern.toString();
pattern = /\/(.+?)\//.exec(pattern)?.[1] ?? ''; // Remove frontslash from front and back of RegExp
pattern = pattern.source.replace(/^\^/, '').replace(/\$$/, '');
Comment thread
ST-DDT marked this conversation as resolved.
Outdated
}
Comment thread
ST-DDT marked this conversation as resolved.

let min: number;
Expand Down
5 changes: 5 additions & 0 deletions test/modules/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,11 @@ describe('helpers', () => {
expect(actual).toHaveLength(9);
expect(actual).toMatch(/^[A-D0-9]{4}-[A-D0-9]{4}$/i);
});

it('hides regex wrapper characters', () => {
const actual = faker.helpers.fromRegExp(/^foo$/i);
expect(actual).toBe('foo');
});
Comment thread
ST-DDT marked this conversation as resolved.
});

describe('shuffle()', () => {
Expand Down
Loading