From 166dd70ef959fb3481512845e8c29b5a092be0fd Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 24 Jan 2024 19:23:39 +0900 Subject: [PATCH] [lib/http] cURL error with non-escaped ampersand on Command Prompt #103 --- lib/http.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/http.js b/lib/http.js index 7248ee2..804acaf 100644 --- a/lib/http.js +++ b/lib/http.js @@ -372,9 +372,9 @@ var HTTPObject = function(engine) { break; default: - console.warn("Switching the engine to cURL. Not supported method in MSXML: " + method); - this.setEngine("CURL"); - console.log("Opened engine:", this.engine); + console.warn("Switching the engine to cURL. Not supported method in MSXML: " + method); + this.setEngine("CURL"); + console.log("Opened engine:", this.engine); } } else { console.log("Opened engine:", this.engine); @@ -390,6 +390,30 @@ var HTTPObject = function(engine) { var responseText = null; var debuggingText = null; + // [lib/http] cURL error with non-escaped ampersand on Command Prompt #103 + var replaceAndExcludeCaretAnd = function(inputString) { + var result = ""; + var i = 0; + + while (i < inputString.length) { + // If the found position is ^&, do not modify and add it as is to the result + if (i < inputString.length - 1 && inputString.slice(i, i + 2) === "^&") { + result += inputString.slice(i, i + 2); + i += 2; + } else { + // Replace & with ^& + if (inputString.charAt(i) === "&") { + result += "^&"; + } else { + result += inputString.charAt(i); + } + i++; + } + } + + return result; + }; + if (this.contentType != null) { this.setHeader("Content-Type", this.contentType); } @@ -478,7 +502,7 @@ var HTTPObject = function(engine) { // Add the request body if this is not GET method if (this.method !== "GET") { cmd.push("-d"); - cmd.push(this.serialize()); + cmd.push(replaceAndExcludeCaretAnd(this.serialize())); } // Add proxy: <[protocol://][user:password@]proxyhost[:port]> @@ -968,7 +992,7 @@ exports.patch = patch; exports.put = put; exports._delete = _delete; -exports.VERSIONINFO = "HTTP Library (http.js) version 0.7.11"; +exports.VERSIONINFO = "HTTP request module (http.js) version 0.7.12"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require;