Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,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 = /\/\^?(.+?)\$?\//.exec(pattern)?.[1] ?? ''; // Remove slash and anchors from front and back of RegExp
}
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