mirror of https://github.com/scrapy/scrapy.git
Merge 8ec0347b27 into b3670369b8
This commit is contained in:
commit
db76727a8b
|
|
@ -23,6 +23,11 @@ class DataAction(argparse.Action):
|
||||||
) -> None:
|
) -> None:
|
||||||
value = str(values)
|
value = str(values)
|
||||||
value = value.removeprefix("$")
|
value = value.removeprefix("$")
|
||||||
|
# curl merges repeated -d/--data/--data-raw options into a single body
|
||||||
|
# joined with "&"; mirror that instead of keeping only the last one.
|
||||||
|
previous = getattr(namespace, self.dest, None)
|
||||||
|
if previous is not None:
|
||||||
|
value = f"{previous}&{value}"
|
||||||
setattr(namespace, self.dest, value)
|
setattr(namespace, self.dest, value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,39 @@ class TestCurlToRequestKwargs:
|
||||||
}
|
}
|
||||||
self._test_command(curl_command, expected_result)
|
self._test_command(curl_command, expected_result)
|
||||||
|
|
||||||
|
def test_post_data_multiple(self):
|
||||||
|
# curl merges repeated -d/--data/--data-raw options into a single body
|
||||||
|
# joined with "&"; scrapy must do the same, not keep only the last one.
|
||||||
|
curl_command = "curl 'https://www.example.org/' -d 'a=1' -d 'b=2' -d 'c=3'"
|
||||||
|
expected_result = {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "https://www.example.org/",
|
||||||
|
"body": "a=1&b=2&c=3",
|
||||||
|
}
|
||||||
|
self._test_command(curl_command, expected_result)
|
||||||
|
|
||||||
|
def test_post_data_multiple_mixed_flag_names(self):
|
||||||
|
curl_command = (
|
||||||
|
"curl 'https://www.example.org/' --data 'a=1' --data-raw 'b=2' -d 'c=3'"
|
||||||
|
)
|
||||||
|
expected_result = {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "https://www.example.org/",
|
||||||
|
"body": "a=1&b=2&c=3",
|
||||||
|
}
|
||||||
|
self._test_command(curl_command, expected_result)
|
||||||
|
|
||||||
|
def test_post_data_multiple_with_string_prefix(self):
|
||||||
|
# The leading "$" left by bash $'...' quoting is stripped per option,
|
||||||
|
# before the values are merged.
|
||||||
|
curl_command = "curl 'https://www.example.org/' -d $'a=1' -d $'b=2'"
|
||||||
|
expected_result = {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "https://www.example.org/",
|
||||||
|
"body": "a=1&b=2",
|
||||||
|
}
|
||||||
|
self._test_command(curl_command, expected_result)
|
||||||
|
|
||||||
def test_explicit_get_with_data(self):
|
def test_explicit_get_with_data(self):
|
||||||
curl_command = "curl httpbin.org/anything -X GET --data asdf"
|
curl_command = "curl httpbin.org/anything -X GET --data asdf"
|
||||||
expected_result = {
|
expected_result = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue