Back
url-encode (clj)
(source)protocol
(url-encode x)
Turn a value into a URL-encoded string.
Examples
hiccup
(ns hiccup.util_test
(:require [clojure.test :refer :all]
[hiccup.util :refer :all])
(:import java.net.URI))
(deftest test-url-encode
(testing "strings"
(are [s e] (= (url-encode s) e)
"a" "a"
"a b" "a+b"
"&" "%26"))
(testing "parameter maps"
(are [m e] (= (url-encode m) e)
{"a" "b"} "a=b"
{:a "b"} "a=b"
(sorted-map :a "b" :c "d") "a=b&c=d"
{:a "&"} "a=%26"
{:é "è"} "%C3%A9=%C3%A8"))
(testing "different encodings"
(are [e s] (= (with-encoding e (url-encode {:iroha "いろは"})) s)
"UTF-8" "iroha=%E3%81%84%E3%82%8D%E3%81%AF"
"Shift_JIS" "iroha=%82%A2%82%EB%82%CD"
"EUC-JP" "iroha=%A4%A4%A4%ED%A4%CF"
"ISO-2022-JP" "iroha=%1B%24%42%24%24%24%6D%24%4F%1B%28%42")))
weavejester/hiccup
(ns hiccup.util_test
(:require [clojure.test :refer :all]
[hiccup.util :refer :all])
(:import java.net.URI))
(deftest test-url-encode
(testing "strings"
(are [s e] (= (url-encode s) e)
"a" "a"
"a b" "a+b"
"&" "%26"))
(testing "parameter maps"
(are [m e] (= (url-encode m) e)
{"a" "b"} "a=b"
{:a "b"} "a=b"
(sorted-map :a "b" :c "d") "a=b&c=d"
{:a "&"} "a=%26"
{:é "è"} "%C3%A9=%C3%A8"))
(testing "different encodings"
(are [e s] (= (with-encoding e (url-encode {:iroha "いろは"})) s)
"UTF-8" "iroha=%E3%81%84%E3%82%8D%E3%81%AF"
"Shift_JIS" "iroha=%82%A2%82%EB%82%CD"
"EUC-JP" "iroha=%A4%A4%A4%ED%A4%CF"
"ISO-2022-JP" "iroha=%1B%24%42%24%24%24%6D%24%4F%1B%28%42")))
pelle/clauth
(ns clauth.test.endpoints
(:require [clojure.test :refer :all]
[clauth
[endpoints :as base]
[client :as client]
[user :as user]
[token :refer :all]
[auth-code :refer :all]]
[hiccup.util :refer :all])
(:import [org.apache.commons.codec.binary Base64]))
(deftest requesting-authorization-code
(reset-token-store!)
(reset-auth-code-store!)
(client/reset-client-store!)
(user/reset-user-store!)
(let [handler (base/authorization-handler)
client (client/register-client)
user (user/register-user "john@example.com" "password")
redirect_uri "http://test.com"
uri "/authorize"
params {:response_type "code"
:client_id (:client-id client)
:redirect_uri redirect_uri
:state "abcde"
:scope "calendar"}
query-string (url-encode params)]
(deftest requesting-implicit-authorization
(reset-token-store!)
(client/reset-client-store!)
(user/reset-user-store!)
(let [handler (base/authorization-handler)
client (client/register-client)
user (user/register-user "john@example.com" "password")
redirect_uri "http://test.com"
uri "/authorize"
params {:response_type "token"
:client_id (:client-id client)
:redirect_uri redirect_uri
:state "abcde"
:scope "calendar"}
query-string (url-encode params)]