Skip to content

Commit

Permalink
Fix JSON request on Windows (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Jun 8, 2020
1 parent 6c62e5b commit 1bf7a21
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 3 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ clone_script:
- cmd: >-
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/borkdude/deps.clj/releases/download/v0.0.9/deps.clj-0.0.9-windows-amd64.zip', 'deps.zip')"
expand-archive -path 'deps.zip'
call deps
powershell -Command "expand-archive -path 'deps.zip' -destination ."
build_script:
- cmd: >-
call deps -A:test
call deps.exe -A:test
9 changes: 8 additions & 1 deletion src/babashka/curl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

;;;; Utils

(def windows? (-> (System/getProperty "os.name")
(str/lower-case)
(str/includes? "win")))

(defn- shell-command
"Executes shell command.
Accepts the following options:
Expand All @@ -19,7 +23,10 @@
`:throw?`: Unless `false`, exits script when the shell-command has a
non-zero exit code, unless `throw?` is set to false."
[args opts]
(let [pb (ProcessBuilder. ^java.util.List args)
(let [args (if windows?
(mapv #(str/replace % "\"" "\\\"") args)
args)
pb (ProcessBuilder. ^java.util.List args)
proc (.start pb)
_ (when-let [is (:in-stream opts)]
(with-open [stdin (.getOutputStream proc)]
Expand Down
8 changes: 8 additions & 0 deletions test/babashka/curl_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
(:body (curl/post "https://postman-echo.com/post"
{:body (io/file "README.md")}))
"babashka.curl")))
(testing "JSON body"
(let [response (curl/post "https://postman-echo.com/post"
{:headers {"Content-Type" "application/json"}
:body (json/generate-string {:a "foo"})})
body (:body response)
body (json/parse-string body true)
json (:json body)]
(is (= {:a "foo"} json))))
(testing "stream body"
(is (str/includes?
(:body (curl/post "https://postman-echo.com/post"
Expand Down

0 comments on commit 1bf7a21

Please sign in to comment.