diff --git a/packages/pluginutils/src/createFilter.ts b/packages/pluginutils/src/createFilter.ts index e8d8899fe..9f2f093f6 100755 --- a/packages/pluginutils/src/createFilter.ts +++ b/packages/pluginutils/src/createFilter.ts @@ -43,9 +43,12 @@ const createFilter: CreateFilter = function createFilter(include?, exclude?, opt const includeMatchers = ensureArray(include).map(getMatcher); const excludeMatchers = ensureArray(exclude).map(getMatcher); + if (!includeMatchers.length && !excludeMatchers.length) + return (id) => typeof id === 'string' && !id.includes('\0'); + return function result(id: string | unknown): boolean { if (typeof id !== 'string') return false; - if (/\0/.test(id)) return false; + if (id.includes('\0')) return false; const pathId = normalizePath(id); diff --git a/packages/pluginutils/src/normalizePath.ts b/packages/pluginutils/src/normalizePath.ts index fa3516f86..cc2ab2e99 100644 --- a/packages/pluginutils/src/normalizePath.ts +++ b/packages/pluginutils/src/normalizePath.ts @@ -2,8 +2,10 @@ import { win32, posix } from 'path'; import type { NormalizePath } from '../types'; +const normalizePathRegExp = new RegExp(`\\${win32.sep}`, 'g'); + const normalizePath: NormalizePath = function normalizePath(filename: string) { - return filename.split(win32.sep).join(posix.sep); + return filename.replace(normalizePathRegExp, posix.sep); }; export { normalizePath as default };