gnh1201 / welsonjs

WelsonJS - Build a Windows app on the Windows built-in JavaScript engine

Home Page:https://catswords.social/@catswords_oss

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

gnh1201 opened this issue · comments

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