Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions packages/pluginutils/src/filter/simple-filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ describe('exactRegex', () => {
expect(regex.test('aFoo')).toBe(false)
})

test('supports hyphens with the Unicode flag', () => {
const regex = exactRegex('foo-bar', 'u')
expect(regex.test('foo-bar')).toBe(true)
expect(regex.test('fooXbar')).toBe(false)
})

test('escapes special characters for Regex', () => {
const regex = exactRegex('foo(bar)')
expect(regex).toStrictEqual(/^foo\(bar\)$/)
Expand Down Expand Up @@ -58,6 +64,12 @@ describe('prefixRegex', () => {
expect(regex.test('aFoo')).toBe(false)
})

test('supports hyphens with the Unicode flag', () => {
const regex = prefixRegex('foo-bar', 'u')
expect(regex.test('foo-bar')).toBe(true)
expect(regex.test('fooXbar')).toBe(false)
})

test('escapes special characters for Regex', () => {
const regex = prefixRegex('foo(bar)')
expect(regex).toStrictEqual(/^foo\(bar\)/)
Expand Down Expand Up @@ -107,6 +119,12 @@ describe('makeIdFiltersToMatchWithQuery', () => {
expect(regex.test('NODE_MODULESa')).toBe(false)
})

test('supports hyphens with the Unicode flag', () => {
const regex = wordRegex('foo-bar', 'u')
expect(regex.test('foo-bar')).toBe(true)
expect(regex.test('fooXbar')).toBe(false)
})

test('escapes special characters for Regex', () => {
const regex = wordRegex('foo.bar')
expect(regex).toStrictEqual(/\bfoo\.bar\b/)
Expand Down
2 changes: 1 addition & 1 deletion packages/pluginutils/src/filter/simple-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function wordRegex(str: string, flags?: string): RegExp {
return new RegExp(`\\b${escapeRegex(str)}\\b`, flags)
}

const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g
const escapeRegexRE = /[/\\^$*+?.()|[\]{}]/g
function escapeRegex(str: string): string {
return str.replace(escapeRegexRE, '\\$&')
}
Expand Down
Loading