Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export function isExclude(name: string, exclude?: FilterPattern): boolean {
return false
}

const ESCAPE_PARENTHESES_REGEX = /[()]/g
const ESCAPE_SPECIAL_CHARS_REGEX = /[()|]/g

export function escapeSpecialChars(str: string): string {
return str.replace(ESCAPE_PARENTHESES_REGEX, '\\$&')
return str.replace(ESCAPE_SPECIAL_CHARS_REGEX, '\\$&')
}
8 changes: 7 additions & 1 deletion test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ResolvedOptions } from '../src'
import { describe, expect, it } from 'vitest'
import { escapeSpecialChars, getNameFromFilePath } from '../src/core/utils'
import { escapeSpecialChars, getNameFromFilePath, matchGlobs } from '../src/core/utils'

describe('getNameFromFilePath', () => {
const options: Partial<ResolvedOptions> = {
Expand All @@ -25,4 +25,10 @@ describe('escapeSpecialChars', () => {
it('should escape parentheses', () => {
expect(escapeSpecialChars('component()')).toBe('component\\(\\)')
})

it('should escape pipes in glob paths', () => {
const glob = escapeSpecialChars('/work/|presentation/components/**/*.vue')

expect(matchGlobs('/work/|presentation/components/Foo.vue', [glob])).toBe(true)
})
})