mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-25 04:44:12 +02:00
fix(importer-curl): keep --data-urlencode whole and survive a stray percent (#597)
This commit is contained in:
@@ -244,6 +244,107 @@ describe("importer-curl", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("Keeps an --data-urlencode value whole", () => {
|
||||
// curl encodes the whole argument, so the `&` and the second `=` are data it
|
||||
// percent-encodes, not separators. Splitting on them made two parameters
|
||||
// out of one, and Yaak then re-sent `q=a&b=c` where curl sends
|
||||
// `q=a%26b%3Dc`. One parameter here re-encodes back to what curl sends.
|
||||
expect(convertCurl(`curl --data-urlencode 'q=a&b=c' https://yaak.app`)).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
method: "POST",
|
||||
url: "https://yaak.app",
|
||||
bodyType: "application/x-www-form-urlencoded",
|
||||
headers: [
|
||||
{
|
||||
name: "Content-Type",
|
||||
value: "application/x-www-form-urlencoded",
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
body: {
|
||||
form: [{ name: "q", value: "a&b=c", enabled: true }],
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Imports a data value that is not valid percent-encoding", () => {
|
||||
// curl sends a `-d` value verbatim and does not require it to decode, so
|
||||
// a lone `%` is an ordinary form value. decodeURIComponent threw URIError
|
||||
// on it and failed the whole import.
|
||||
expect(convertCurl(`curl -d 'a=100%' https://yaak.app`)).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
method: "POST",
|
||||
url: "https://yaak.app",
|
||||
bodyType: "application/x-www-form-urlencoded",
|
||||
headers: [
|
||||
{
|
||||
name: "Content-Type",
|
||||
value: "application/x-www-form-urlencoded",
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
body: {
|
||||
form: [{ name: "a", value: "100%", enabled: true }],
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Keeps a valid escape decoded when the value also holds a stray percent", () => {
|
||||
// Handing the whole value back untouched would leave `%25` to be encoded a
|
||||
// second time on send, so each valid run decodes on its own.
|
||||
expect(convertCurl(`curl -d 'a=50%25 and 100%' https://yaak.app`)).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
method: "POST",
|
||||
url: "https://yaak.app",
|
||||
bodyType: "application/x-www-form-urlencoded",
|
||||
headers: [
|
||||
{
|
||||
name: "Content-Type",
|
||||
value: "application/x-www-form-urlencoded",
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
body: {
|
||||
form: [{ name: "a", value: "50% and 100%", enabled: true }],
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Decodes -G --data-urlencode into the query string", () => {
|
||||
// `-G` puts the data in the query string, which is encoded on send just
|
||||
// like the form body, so the value has to arrive here decoded or it goes
|
||||
// out encoded twice.
|
||||
expect(convertCurl(`curl -G --data-urlencode 'q=a&b' https://yaak.app`)).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
url: "https://yaak.app",
|
||||
urlParameters: [{ name: "q", value: "a&b", enabled: true }],
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Imports data params as text", () => {
|
||||
expect(
|
||||
convertCurl("curl -H Content-Type:text/plain -d a -d b -d c=ccc https://yaak.app"),
|
||||
|
||||
Reference in New Issue
Block a user