@@ -4,21 +4,35 @@ exports.unescape = void 0;
44/**
55 * Un-escape a string that has been escaped with {@link escape}.
66 *
7- * If the {@link windowsPathsNoEscape} option is used, then square-brace
8- * escapes are removed, but not backslash escapes. For example, it will turn
9- * the string `'[*]'` into `*`, but it will not turn `'\\*'` into `'*'`,
10- * becuase `\` is a path separator in `windowsPathsNoEscape` mode.
7+ * If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then
8+ * square-bracket escapes are removed, but not backslash escapes.
119 *
12- * When `windowsPathsNoEscape` is not set, then both brace escapes and
10+ * For example, it will turn the string `'[*]'` into `*`, but it will not
11+ * turn `'\\*'` into `'*'`, because `\` is a path separator in
12+ * `windowsPathsNoEscape` mode.
13+ *
14+ * When `windowsPathsNoEscape` is not set, then both square-bracket escapes and
1315 * backslash escapes are removed.
1416 *
1517 * Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
1618 * or unescaped.
19+ *
20+ * When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be
21+ * unescaped.
1722 */
18- const unescape = ( s , { windowsPathsNoEscape = false , } = { } ) => {
23+ const unescape = ( s , { windowsPathsNoEscape = false , magicalBraces = true , } = { } ) => {
24+ if ( magicalBraces ) {
25+ return windowsPathsNoEscape
26+ ? s . replace ( / \[ ( [ ^ \/ \\ ] ) \] / g, '$1' )
27+ : s
28+ . replace ( / ( (? ! \\ ) .| ^ ) \[ ( [ ^ \/ \\ ] ) \] / g, '$1$2' )
29+ . replace ( / \\ ( [ ^ \/ ] ) / g, '$1' ) ;
30+ }
1931 return windowsPathsNoEscape
20- ? s . replace ( / \[ ( [ ^ \/ \\ ] ) \] / g, '$1' )
21- : s . replace ( / ( (? ! \\ ) .| ^ ) \[ ( [ ^ \/ \\ ] ) \] / g, '$1$2' ) . replace ( / \\ ( [ ^ \/ ] ) / g, '$1' ) ;
32+ ? s . replace ( / \[ ( [ ^ \/ \\ { } ] ) \] / g, '$1' )
33+ : s
34+ . replace ( / ( (? ! \\ ) .| ^ ) \[ ( [ ^ \/ \\ { } ] ) \] / g, '$1$2' )
35+ . replace ( / \\ ( [ ^ \/ { } ] ) / g, '$1' ) ;
2236} ;
2337exports . unescape = unescape ;
2438//# sourceMappingURL=unescape.js.map
0 commit comments