diff --git a/README.md b/README.md index be608742..62d5cb7a 100644 --- a/README.md +++ b/README.md @@ -272,10 +272,10 @@ Returns the path with escaped special characters depending on the platform. * `@+!` before the opening parenthesis; * `\\` before non-special characters; * Windows: - * `(){}` + * `(){}[]` * `!` at the beginning of line; * `@+!` before the opening parenthesis; - * Characters like `*?|[]` cannot be used in the path ([windows_naming_conventions][windows_naming_conventions]), so they will not be escaped; + * Characters like `*?|` cannot be used in the path ([windows_naming_conventions][windows_naming_conventions]), so they will not be escaped; ```js fg.escapePath('!abc'); @@ -294,7 +294,7 @@ fg.win32.escapePath('C:\\Program Files (x86)\\**\\*'); Converts a path to a pattern depending on the platform, including special character escaping. * Posix. Works similarly to the `fg.posix.escapePath` method. -* Windows. Works similarly to the `fg.win32.escapePath` method, additionally converting backslashes to forward slashes in cases where they are not escape characters (`!()+@{}`). +* Windows. Works similarly to the `fg.win32.escapePath` method, additionally converting backslashes to forward slashes in cases where they are not escape characters (`!()+@{}[]`). ```js fg.convertPathToPattern('[OpenSource] mrmlnc – fast-glob (Deluxe Edition) 2014') + '/*.flac'; diff --git a/src/utils/path.spec.ts b/src/utils/path.spec.ts index 770ad317..3b4f36bd 100644 --- a/src/utils/path.spec.ts +++ b/src/utils/path.spec.ts @@ -63,6 +63,7 @@ describe('Utils → Path', () => { assert.strictEqual(util.escapeWindowsPath('!abc'), '\\!abc'); assert.strictEqual(util.escapeWindowsPath('()'), '\\(\\)'); assert.strictEqual(util.escapeWindowsPath('{}'), '\\{\\}'); + assert.strictEqual(util.escapeWindowsPath('[]'), '\\[\\]'); assert.strictEqual(util.escapeWindowsPath('@('), '\\@\\('); assert.strictEqual(util.escapeWindowsPath('!('), '\\!\\('); assert.strictEqual(util.escapeWindowsPath('+('), '\\+\\('); @@ -113,6 +114,8 @@ describe('Utils → Path', () => { assert.strictEqual(util.convertWindowsPathToPattern('\\)\\'), '\\)/'); assert.strictEqual(util.convertWindowsPathToPattern('\\{\\'), '\\{/'); assert.strictEqual(util.convertWindowsPathToPattern('\\}\\'), '\\}/'); + assert.strictEqual(util.convertWindowsPathToPattern('\\[\\'), '\\[/'); + assert.strictEqual(util.convertWindowsPathToPattern('\\]\\'), '\\]/'); assert.strictEqual(util.convertWindowsPathToPattern('.\\*'), './*'); assert.strictEqual(util.convertWindowsPathToPattern('.\\**'), './**'); diff --git a/src/utils/path.ts b/src/utils/path.ts index 11dda077..4cfb6e41 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -7,11 +7,11 @@ const IS_WINDOWS_PLATFORM = os.platform() === 'win32'; const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\ /** * All non-escaped special characters. - * Posix: ()*?[\]{|}, !+@ before (, ! at the beginning, \\ before non-special characters. - * Windows: (){}, !+@ before (, ! at the beginning. + * Posix: ()*?[]{|}, !+@ before (, ! at the beginning, \\ before non-special characters. + * Windows: (){}[], !+@ before (, ! at the beginning. */ const POSIX_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\()|\\(?![!()*+?@[\]{|}]))/g; -const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([(){}]|^!|[!+@](?=\())/g; +const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()[\]{}]|^!|[!+@](?=\())/g; /** * The device path (\\.\ or \\?\). * https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths @@ -22,7 +22,7 @@ const DOS_DEVICE_PATH_RE = /^\\\\([.?])/; * Windows: !()+@{} * https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions */ -const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@{}])/g; +const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@[\]{}])/g; /** * Designed to work only with simple paths: `dir\\file`.