Fix #1596: Escape URLs for clojure.java.browse/browse-url on Windows (#1597)

This commit is contained in:
Chuck Cassel 2023-08-08 04:49:07 -04:00 committed by GitHub
parent d1e36be9d9
commit 3370d7a063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View file

@ -10,6 +10,7 @@ A preview of the next release can be installed from
## Unreleased
- [#1592](https://github.com/babashka/babashka/issues/1592): expose `sci.core` in babashka
- [#1596](https://github.com/babashka/babashka/issues/1596): Fix `clojure.java.browse/browse-url` truncates URLs with multiple query parameters on Windows
## 1.3.182 (2023-07-20)

View file

@ -25,7 +25,7 @@
(case os
:mac (sh "open" url)
:linux (sh "xdg-open" url)
:windows (sh "cmd" "/C" "start" url)))))
:windows (sh "cmd" "/C" "start" (.replace url "&" "^&"))))))
(def browse-namespace
{'*open-url-script* open-url-script

View file

@ -0,0 +1,25 @@
(ns babashka.impl.clojure.java.browse-test
(:require
[babashka.test-utils :refer [bb]]
[cheshire.core :as json]
[clojure.test :refer [deftest is]]
[org.httpkit.server :as http]))
(def ^:dynamic *http-port* 1234)
(deftest browse-url-test
(let [p (promise)
stop-server (http/run-server (fn [{:keys [query-string]}]
(let [params (apply hash-map (mapcat #(.split % "=") (.split query-string "&")))]
(deliver p params)
{:status 200
:content-type "application/json"
:body (json/encode params)}))
{:port *http-port*})]
(try
(bb nil
(str "(clojure.java.browse/browse-url \"http://localhost:" *http-port* "?arg1=v1&arg2=v2\")"))
(is (= {"arg1" "v1"
"arg2" "v2"}
(deref p 5000 ::timeout)))
(finally (stop-server :timeout 1000)))))