This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-15
Channels
- # aleph (1)
- # announcements (7)
- # beginners (6)
- # calva (24)
- # cider (18)
- # clj-otel (1)
- # clojars (8)
- # clojure (22)
- # clojure-dev (11)
- # clojure-europe (52)
- # clojure-finland (12)
- # clojure-nl (1)
- # clojure-norway (28)
- # clojure-uk (7)
- # clojured (1)
- # cursive (6)
- # datomic (1)
- # events (1)
- # humbleui (41)
- # hyperfiddle (75)
- # lsp (46)
- # malli (34)
- # matrix (1)
- # off-topic (16)
- # releases (1)
- # shadow-cljs (12)
- # squint (11)
- # timbre (1)
- # tools-deps (24)
I always get entangled into the rules of URL parameter encoding and cannot make sense of this. If I have URL parameter my param
and value & & &%%%%
I have to form encode the key and value of the param, so I get this URL: /?my+param=%26+%26+%26%25%25%25%25
but then if I put it into URI only part of it gets decoded:
(bean (URI. "/?my+param=%26+%26+%26%25%25%25%25"))
=>
{:path "/",
:rawQuery "my+param=%26+%26+%26%25%25%25%25",
:fragment nil,
:authority nil,
:rawAuthority nil,
:port -1,
:absolute false,
:host nil,
:rawPath "/",
:opaque false,
:rawSchemeSpecificPart "/?my+param=%26+%26+%26%25%25%25%25",
:class java.net.URI,
:rawUserInfo nil,
:query "my+param=&+&+&%%%%",
:rawFragment nil,
:scheme nil,
:userInfo nil,
:schemeSpecificPart "/?my+param=&+&+&%%%%"}
Why is that? I always get tripped up by this encoding stuff.URLs and URIs are not the same
user=> (codec/form-decode (.getQuery (java.net.URL. "")))
{"my param" "=& & &%%%%"}
user=> (codec/form-decode (.getQuery (java.net.URI. "")))
{"my param" "=", " " ["" ""]}
user=>
Interesting… really haven’t considered that
#?(:clj (:import [java.util Base64]))
is what i have been using lately, and one on the clojurescript side from the goog.crypto
The issue I am running into now is that URL doesn’t support relative paths
I want to parse parameters out of an URL correctly
It gets worse:
(codec/form-decode (.getQuery (URI. "/?my+param=%26+%26+%26%25%25%25%25")))
=> {"my param" "", " " ["" ""]}
Shouldn't space be encoded %20 and not plus?
That’s what ring.util.codec/form-encode produces
And + is valid as space in URLs
Another problem is if you have =
in there:
(bean (URI. "/?my+param=%3D%26+%26+%26%25%25%25%25"))
=>
{:path "/",
:rawQuery "my+param=%3D%26+%26+%26%25%25%25%25",
:fragment nil,
:authority nil,
:rawAuthority nil,
:port -1,
:absolute false,
:host nil,
:rawPath "/",
:opaque false,
:rawSchemeSpecificPart "/?my+param=%3D%26+%26+%26%25%25%25%25",
:class java.net.URI,
:rawUserInfo nil,
:query "my+param==&+&+&%%%%",
:rawFragment nil,
:scheme nil,
:userInfo nil,
:schemeSpecificPart "/?my+param==&+&+&%%%%"}
(just a friendly admin reminder to use threads for answers please @julian608 @roklenarcic)