From 8561f3c18994a27202e44404a16394273a7d06fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Wed, 13 Mar 2024 13:39:18 +0100 Subject: [PATCH] fix(request-snipppets): fix issues in escaping Powershell (#9692) --- src/core/plugins/request-snippets/fn.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/core/plugins/request-snippets/fn.js b/src/core/plugins/request-snippets/fn.js index 7244eef6703..8fe7f539ccd 100644 --- a/src/core/plugins/request-snippets/fn.js +++ b/src/core/plugins/request-snippets/fn.js @@ -50,15 +50,14 @@ const escapePowershell = (str) => { return str } if (/\n/.test(str)) { - return "@\"\n" + str.replace(/"/g, "\\\"").replace(/`/g, "``").replace(/\$/, "`$") + "\n\"@" + const escaped = str.replace(/`/g, "``").replace(/\$/g, "`$") + return `@"\n${escaped}\n"@` } - // eslint-disable-next-line no-useless-escape - if (!/^[_\/-]/g.test(str)) - return "'" + str - .replace(/"/g, "\"\"") - .replace(/'/g, "''") + "'" - else - return str + if (!/^[_\/-]/.test(str)) { // eslint-disable-line no-useless-escape + const escaped = str.replace(/'/g, "''") + return `'${escaped}'` + } + return str } function getStringBodyOfMap(request) {