Comments about differences to reitit.impl

This commit is contained in:
Juho Teperi 2023-03-24 13:59:02 +02:00
parent dad8f530a6
commit e2217887e3
2 changed files with 20 additions and 3 deletions

View file

@ -30,6 +30,9 @@
new-query (if (fn? new-query-or-update-fn)
(new-query-or-update-fn (query-params uri))
new-query-or-update-fn)]
;; NOTE: Differences to reitit.impl/query-string?
;; reitit fn adds "=" even if value is empty string
;; reitit encodes " " as "+" while browser and goog.Uri encode as "%20"
(.setQueryData uri (goog.Uri.QueryData/createFromMap (clj->js new-query)))
(.toString uri)))

View file

@ -6,7 +6,8 @@
[schema.core :as s]
[reitit.coercion.schema :as rcs]
[reitit.coercion.malli :as rcm]
[reitit.frontend.test-utils :refer [capture-console]]))
[reitit.frontend.test-utils :refer [capture-console]]
[reitit.impl :as impl]))
(deftest query-params-test
(is (= {:foo "1"}
@ -244,7 +245,17 @@
(deftest set-query-params-test
(is (= "foo?bar=1"
(rf/set-query-params "foo" {:bar 1})
(rf/set-query-params "foo" #(assoc % :bar 1))))
(rf/set-query-params "foo" #(assoc % :bar 1))
;; Also compare to reitit.impl version which is used by match->path (and history fns)
(str "foo?" (impl/query-string {:bar 1}))))
(testing "Encoding"
(is (= "foo?bar=foo%20bar"
(rf/set-query-params "foo" {:bar "foo bar"})
(rf/set-query-params "foo" #(assoc % :bar "foo bar"))
;; FIXME: Reitit.impl encodes space as "+"
; (str "foo?" (impl/query-string {:bar "foo bar"}))
)))
(testing "Keep fragment"
(is (= "foo?bar=1&zzz=2#aaa"
@ -260,7 +271,10 @@
(rf/set-query-params "foo?asd=1&bar" #(dissoc % :asd))))
(is (= "foo?bar"
(rf/set-query-params "foo" #(assoc % :bar ""))))
(rf/set-query-params "foo" #(assoc % :bar ""))
;; FIXME: Reitit.impl adds "=" for empty string values
; (str "foo?" (impl/query-string {:bar ""}))
))
(is (= "foo"
(rf/set-query-params "foo?asd=1" #(dissoc % :asd))))