diff --git a/lib/curl_req/macro.ex b/lib/curl_req/macro.ex index d601fff..b699b1a 100644 --- a/lib/curl_req/macro.ex +++ b/lib/curl_req/macro.ex @@ -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 diff --git a/test/curl_req/macro_test.exs b/test/curl_req/macro_test.exs index 53e25e2..81f5878 100644 --- a/test/curl_req/macro_test.exs +++ b/test/curl_req/macro_test.exs @@ -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