Skip to content

Commit

Permalink
Handle newlines ending in backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
derekkraan committed Jul 25, 2024
1 parent d178f34 commit 5fe305b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/curl_req/macro.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ defmodule CurlReq.Macro do
command
|> String.trim()
|> String.trim_leading("curl")
|> String.replace("\\\n", " ")
|> String.replace("\n", " ")

{options, rest, _invalid} =
command
Expand Down
50 changes: 50 additions & 0 deletions test/curl_req/macro_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,55 @@ defmodule CurlReq.MacroTest do
response_steps: [redirect: &Req.Steps.redirect/1]
}
end

test "accepts newlines ending in backslash" do
uri = URI.parse("https://hello.myshopify.com/api/2024-07/graphql.json")

assert %Req.Request{
method: :post,
url: ^uri,
headers: %{"content-type" => ["application/json"]}
} = ~CURL"""
curl -X POST \
https://hello.myshopify.com/api/2024-07/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Storefront-Access-Token: ABCDEF' \
-d '{
"query": "{
products(first: 3) {
edges {
node {
id
title
}
}
}
}"
}'
"""

assert %Req.Request{
method: :post,
url: ^uri,
headers: %{"content-type" => ["application/json"]}
} = ~CURL"""
curl -X POST
https://hello.myshopify.com/api/2024-07/graphql.json
-H 'Content-Type: application/json'
-H 'X-Shopify-Storefront-Access-Token: ABCDEF'
-d '{
"query": "{
products(first: 3) {
edges {
node {
id
title
}
}
}
}"
}'
"""
end
end
end

0 comments on commit 5fe305b

Please sign in to comment.