gnh1201 / welsonjs

WelsonJS - Build a Windows app on the Windows built-in JavaScript engine
https://catswords.social/@catswords_oss
GNU General Public License v3.0
226 stars 15 forks source link

[lib/http] cURL error with non-escaped ampersand on Command Prompt #103

Closed gnh1201 closed 9 months ago

gnh1201 commented 9 months ago

Summary

In cURL-based HTTP requests, if a query string with the "&"(non-escaped ampersand) character is included within JSON data, errors may occur in the command prompt.

For example:

var response = HTTP.create("CURL")
    .setBearerAuth("<token>")
    .setHeader("Accept", "application/json")
    .setContentType("application/json")
    .requestBody({
        "url": "https://exmaple.org?foo=1&bar=2"   // error
    })
    .put("https://exmaple.org")   // equals with: open("https://exmaple.org").send()
    .responseBody
;
console.log(JSON.stringify(response));

As a result:

> curl -X PUT <...> -d "{\"url\": \"https://exmaple.org?foo=1&bar=2\"}" https://exmaple.org
                                                             ^ (error)
bar is not valid command
gnh1201 commented 9 months ago

https://chat.openai.com/c/56b9b536-d13f-4834-b740-999a0d21dca6

gnh1201 commented 9 months ago

Done