mirror of
https://github.com/nodejs/node.git
synced 2025-08-18 07:08:50 +02:00

PR-URL: https://github.com/nodejs/node/pull/52351 Reviewed-By: Luke Karrys <luke@lukekarrys.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
18 lines
No EOL
848 B
JavaScript
18 lines
No EOL
848 B
JavaScript
/**
|
|
* Escape all magic characters in a glob pattern.
|
|
*
|
|
* If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape}
|
|
* option is used, then characters are escaped by wrapping in `[]`, because
|
|
* a magic character wrapped in a character class can only be satisfied by
|
|
* that exact character. In this mode, `\` is _not_ escaped, because it is
|
|
* not interpreted as a magic character, but instead as a path separator.
|
|
*/
|
|
export const escape = (s, { windowsPathsNoEscape = false, } = {}) => {
|
|
// don't need to escape +@! because we escape the parens
|
|
// that make those magic, and escaping ! as [!] isn't valid,
|
|
// because [!]] is a valid glob class meaning not ']'.
|
|
return windowsPathsNoEscape
|
|
? s.replace(/[?*()[\]]/g, '[$&]')
|
|
: s.replace(/[?*()[\]\\]/g, '\\$&');
|
|
};
|
|
//# sourceMappingURL=escape.js.map
|