From 90e0007478830b16c69f9b7f1e8ed0a7b72fa8ac Mon Sep 17 00:00:00 2001 From: Ryan Fowler Date: Tue, 30 Oct 2018 07:53:43 -0600 Subject: [PATCH] Allow a mix of keyword and string keys in :query url/parse returns a query-map of strings to strings and the README provides examples of associng keyword keys into the query map. Using these features in combination caused the sort in map->query to blow up with a ClassCastException. --- src/cemerick/url.cljx | 2 +- test/cemerick/test_url.cljx | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cemerick/url.cljx b/src/cemerick/url.cljx index 75ff53d..9629181 100644 --- a/src/cemerick/url.cljx +++ b/src/cemerick/url.cljx @@ -29,7 +29,7 @@ (defn map->query [m] (some->> (seq m) - sort ; sorting makes testing a lot easier :-) + (sort-by (fn [[k v]] (name k))) ; sorting makes testing a lot easier :-) (map (fn [[k v]] [(url-encode (name k)) "=" diff --git a/test/cemerick/test_url.cljx b/test/cemerick/test_url.cljx index fe2e6d1..0856d7e 100644 --- a/test/cemerick/test_url.cljx +++ b/test/cemerick/test_url.cljx @@ -47,6 +47,12 @@ nil nil "" nil)) +(deftest query-mixed-keys + (is (= "https://localhost:80?baz=bam&foo=bar" + (-> (url "https://localhost:80?foo=bar") + (assoc-in [:query :baz] "bam") + str)))) + (deftest user-info-edgecases (are [user-info url-string] (= user-info ((juxt :username :password) (url url-string))) ["a" nil] "http://a@foo"