MCPcopy Create free account
hub / github.com/Azure/powershell / _windowsQuoteCmdArg

Method _windowsQuoteCmdArg

lib/index.js:1889–2008  ·  view source on GitHub ↗
(arg)

Source from the content-addressed store, hash-verified

1887 this._endsWith(upperToolPath, '.BAT'));
1888 }
1889 _windowsQuoteCmdArg(arg) {
1890 // for .exe, apply the normal quoting rules that libuv applies
1891 if (!this._isCmdFile()) {
1892 return this._uvQuoteCmdArg(arg);
1893 }
1894 // otherwise apply quoting rules specific to the cmd.exe command line parser.
1895 // the libuv rules are generic and are not designed specifically for cmd.exe
1896 // command line parser.
1897 //
1898 // for a detailed description of the cmd.exe command line parser, refer to
1899 // http://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts/7970912#7970912
1900 // need quotes for empty arg
1901 if (!arg) {
1902 return '""';
1903 }
1904 // determine whether the arg needs to be quoted
1905 const cmdSpecialChars = [
1906 ' ',
1907 '\t',
1908 '&',
1909 '(',
1910 ')',
1911 '[',
1912 ']',
1913 '{',
1914 '}',
1915 '^',
1916 '=',
1917 ';',
1918 '!',
1919 "'",
1920 '+',
1921 ',',
1922 '`',
1923 '~',
1924 '|',
1925 '<',
1926 '>',
1927 '"'
1928 ];
1929 let needsQuotes = false;
1930 for (const char of arg) {
1931 if (cmdSpecialChars.some(x => x === char)) {
1932 needsQuotes = true;
1933 break;
1934 }
1935 }
1936 // short-circuit if quotes not needed
1937 if (!needsQuotes) {
1938 return arg;
1939 }
1940 // the following quoting rules are very similar to the rules that by libuv applies.
1941 //
1942 // 1) wrap the string in quotes
1943 //
1944 // 2) double-up quotes - i.e. " => ""
1945 //
1946 // this is different from the libuv quoting rules. libuv replaces " with \", which unfortunately

Callers 2

_getCommandStringMethod · 0.95
_getSpawnArgsMethod · 0.95

Calls 2

_isCmdFileMethod · 0.95
_uvQuoteCmdArgMethod · 0.95

Tested by

no test coverage detected