123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 'use strict';
- const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
- function escapeCommand(arg) {
-
- arg = arg.replace(metaCharsRegExp, '^$1');
- return arg;
- }
- function escapeArgument(arg, doubleEscapeMetaChars) {
-
- arg = `${arg}`;
-
-
-
- arg = arg.replace(/(\\*)"/g, '$1$1\\"');
-
-
-
- arg = arg.replace(/(\\*)$/, '$1$1');
-
-
- arg = `"${arg}"`;
-
- arg = arg.replace(metaCharsRegExp, '^$1');
-
- if (doubleEscapeMetaChars) {
- arg = arg.replace(metaCharsRegExp, '^$1');
- }
- return arg;
- }
- module.exports.command = escapeCommand;
- module.exports.argument = escapeArgument;
|