Skip to content

Commit

Permalink
feat(functions): add support unicode to regexp pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasilii Mikhailovskii committed Dec 4, 2023
1 parent 1d38446 commit 510fc5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/functions/src/__tests__/pattern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ describe('Core Functions / Pattern', () => {
it('should return empty array when given value does not match the given notMatch string regex with slashes and modifier', async () => {
expect(await runPattern('def', { notMatch: '/[abc]+/i' })).toEqual([]);
});

it('should support unicode', async () => {
expect(await runPattern('DüsseldorfKölnМосква北京市إسرائيل', { match: '^\\p{Letter}+$' })).toEqual([]);
expect(await runPattern('DüsseldorfKölnМосква北京市إسرائيل', { match: '/^\\p{Letter}+$/u' })).toEqual([]);
});
});

describe('given match and notMatch regexes', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function createRegex(pattern: string): RegExp {
return new RegExp(splitRegex[1], splitRegex[2]);
} else {
// without slashes like [a-b]+
return new RegExp(pattern);
return new RegExp(pattern, 'u');
}
}

Expand Down

0 comments on commit 510fc5a

Please sign in to comment.