Skip to content

Commit 8638dc6

Browse files
committed
fix: escape square braces on Windows platform
1 parent 91dc88a commit 8638dc6

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ Returns the path with escaped special characters depending on the platform.
272272
* `@+!` before the opening parenthesis;
273273
* `\\` before non-special characters;
274274
* Windows:
275-
* `(){}`
275+
* `(){}[]`
276276
* `!` at the beginning of line;
277277
* `@+!` before the opening parenthesis;
278-
* Characters like `*?|[]` cannot be used in the path ([windows_naming_conventions][windows_naming_conventions]), so they will not be escaped;
278+
* Characters like `*?|` cannot be used in the path ([windows_naming_conventions][windows_naming_conventions]), so they will not be escaped;
279279

280280
```js
281281
fg.escapePath('!abc');
@@ -294,7 +294,7 @@ fg.win32.escapePath('C:\\Program Files (x86)\\**\\*');
294294
Converts a path to a pattern depending on the platform, including special character escaping.
295295

296296
* Posix. Works similarly to the `fg.posix.escapePath` method.
297-
* Windows. Works similarly to the `fg.win32.escapePath` method, additionally converting backslashes to forward slashes in cases where they are not escape characters (`!()+@{}`).
297+
* Windows. Works similarly to the `fg.win32.escapePath` method, additionally converting backslashes to forward slashes in cases where they are not escape characters (`!()+@{}[]`).
298298

299299
```js
300300
fg.convertPathToPattern('[OpenSource] mrmlnc – fast-glob (Deluxe Edition) 2014') + '/*.flac';

src/utils/path.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('Utils → Path', () => {
6363
assert.strictEqual(util.escapeWindowsPath('!abc'), '\\!abc');
6464
assert.strictEqual(util.escapeWindowsPath('()'), '\\(\\)');
6565
assert.strictEqual(util.escapeWindowsPath('{}'), '\\{\\}');
66+
assert.strictEqual(util.escapeWindowsPath('[]'), '\\[\\]');
6667
assert.strictEqual(util.escapeWindowsPath('@('), '\\@\\(');
6768
assert.strictEqual(util.escapeWindowsPath('!('), '\\!\\(');
6869
assert.strictEqual(util.escapeWindowsPath('+('), '\\+\\(');
@@ -113,6 +114,8 @@ describe('Utils → Path', () => {
113114
assert.strictEqual(util.convertWindowsPathToPattern('\\)\\'), '\\)/');
114115
assert.strictEqual(util.convertWindowsPathToPattern('\\{\\'), '\\{/');
115116
assert.strictEqual(util.convertWindowsPathToPattern('\\}\\'), '\\}/');
117+
assert.strictEqual(util.convertWindowsPathToPattern('\\[\\'), '\\[/');
118+
assert.strictEqual(util.convertWindowsPathToPattern('\\]\\'), '\\]/');
116119

117120
assert.strictEqual(util.convertWindowsPathToPattern('.\\*'), './*');
118121
assert.strictEqual(util.convertWindowsPathToPattern('.\\**'), './**');

src/utils/path.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
77
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
88
/**
99
* All non-escaped special characters.
10-
* Posix: ()*?[\]{|}, !+@ before (, ! at the beginning, \\ before non-special characters.
11-
* Windows: (){}, !+@ before (, ! at the beginning.
10+
* Posix: ()*?[]{|}, !+@ before (, ! at the beginning, \\ before non-special characters.
11+
* Windows: (){}[], !+@ before (, ! at the beginning.
1212
*/
1313
const POSIX_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\()|\\(?![!()*+?@[\]{|}]))/g;
14-
const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([(){}]|^!|[!+@](?=\())/g;
14+
const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()[\]{}]|^!|[!+@](?=\())/g;
1515
/**
1616
* The device path (\\.\ or \\?\).
1717
* https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths
@@ -22,7 +22,7 @@ const DOS_DEVICE_PATH_RE = /^\\\\([.?])/;
2222
* Windows: !()+@{}
2323
* https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
2424
*/
25-
const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@{}])/g;
25+
const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@[\]{}])/g;
2626

2727
/**
2828
* Designed to work only with simple paths: `dir\\file`.

0 commit comments

Comments
 (0)