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

Method _uvQuoteCmdArg

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

Source from the content-addressed store, hash-verified

2007 .join('');
2008 }
2009 _uvQuoteCmdArg(arg) {
2010 // Tool runner wraps child_process.spawn() and needs to apply the same quoting as
2011 // Node in certain cases where the undocumented spawn option windowsVerbatimArguments
2012 // is used.
2013 //
2014 // Since this function is a port of quote_cmd_arg from Node 4.x (technically, lib UV,
2015 // see https://github.com/nodejs/node/blob/v4.x/deps/uv/src/win/process.c for details),
2016 // pasting copyright notice from Node within this function:
2017 //
2018 // Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2019 //
2020 // Permission is hereby granted, free of charge, to any person obtaining a copy
2021 // of this software and associated documentation files (the "Software"), to
2022 // deal in the Software without restriction, including without limitation the
2023 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2024 // sell copies of the Software, and to permit persons to whom the Software is
2025 // furnished to do so, subject to the following conditions:
2026 //
2027 // The above copyright notice and this permission notice shall be included in
2028 // all copies or substantial portions of the Software.
2029 //
2030 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2031 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2032 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2033 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2034 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2035 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2036 // IN THE SOFTWARE.
2037 if (!arg) {
2038 // Need double quotation for empty argument
2039 return '""';
2040 }
2041 if (!arg.includes(' ') && !arg.includes('\t') && !arg.includes('"')) {
2042 // No quotation needed
2043 return arg;
2044 }
2045 if (!arg.includes('"') && !arg.includes('\\')) {
2046 // No embedded double quotes or backslashes, so I can just wrap
2047 // quote marks around the whole thing.
2048 return `"${arg}"`;
2049 }
2050 // Expected input/output:
2051 // input : hello"world
2052 // output: "hello\"world"
2053 // input : hello""world
2054 // output: "hello\"\"world"
2055 // input : hello\world
2056 // output: hello\world
2057 // input : hello\\world
2058 // output: hello\\world
2059 // input : hello\"world
2060 // output: "hello\\\"world"
2061 // input : hello\\"world
2062 // output: "hello\\\\\"world"
2063 // input : hello world\
2064 // output: "hello world\\" - note the comment in libuv actually reads "hello world\"
2065 // but it appears the comment is wrong, it should be "hello world\\"
2066 let reverse = '"';

Callers 1

_windowsQuoteCmdArgMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected