lambdaisland / uri

A pure Clojure/ClojureScript URI library
Mozilla Public License 2.0
243 stars 21 forks source link

Query param space encoding is inconsistent #16

Closed mrrodriguez closed 4 years ago

mrrodriguez commented 4 years ago

The follow is unexpected behavior:

(require '[lambdaisland.uri :as uri])

(-> "/foo"
    (uri/assoc-query* {:a "a b"})
    (uri/assoc-query* {:b "b c"}))
;;= returns
{:scheme nil,
 :user nil,
 :password nil,
 :host nil,
 :port nil, 
 :path "/foo", 
 :query "a=a%2Bb&b=b+c", 
 :fragment nil}

Notice that :query has confusion around the "+" that is used to encode spaces. This is because all of the "decoding" side query param functions do not take into account the "+".

Another example:

(-> "/foo"
    (uri/assoc-query* {:a "a b"})
    uri/query-map)
;;= {:a "a+b"}

The "+" character is never decoded.

Is this intentional behavior and the expectation is the consumer is careful to always remove "+" at the "right time"?

plexus commented 4 years ago

Definitely a bug. I'll fix it.

plexus commented 4 years ago

Fixed in 1.4.54. Please close this issue if you've confirmed this fixes things for you. I've added generative testing to make sure encode/decode match up.

mrrodriguez commented 4 years ago

@plexus thanks for the fast response! I will test out with the new version and confirm here. Noting the changes are here https://github.com/lambdaisland/uri/commit/5780e3caf04dd062d77d389d5f92428b74135455 (for future reference)

mrrodriguez commented 4 years ago

Update: This has been working for me. Thanks for making the changes! I'll close now.