Skip to content

Commit

Permalink
Replace the form decoder with URLCodec
Browse files Browse the repository at this point in the history
- This addresses the following URLdecoding issue
ring-clojure/ring#269
  • Loading branch information
iku000888 committed Dec 7, 2016
1 parent 94a4647 commit 6b6f581
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/ring/util/codec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
(:import java.io.File
java.util.Map
[java.net URLEncoder URLDecoder]
org.apache.commons.codec.binary.Base64))
org.apache.commons.codec.binary.Base64
org.apache.commons.codec.net.URLCodec))

(defn assoc-conj
"Associate a key with a value in a map. If the key already exists in the map,
a vector of values is associated with the key."
[map key val]
(assoc map key
(if-let [cur (get map key)]
(if (vector? cur)
(conj cur val)
[cur val])
val)))
(if-let [cur (get map key)]
(if (vector? cur)
(conj cur val)
[cur val])
val)))

(defn- double-escape [^String x]
(.replace (.replace x "\\" "\\\\") "$" "\\$"))
Expand Down Expand Up @@ -58,9 +59,9 @@
encoding or UTF-8 by default."
[unencoded & [encoding]]
(str/replace
unencoded
#"[^A-Za-z0-9_~.+-]+"
#(double-escape (percent-encode % encoding))))
unencoded
#"[^A-Za-z0-9_~.+-]+"
#(double-escape (percent-encode % encoding))))

(defn ^String url-decode
"Returns the url-decoded version of the given string, using either a specified
Expand Down Expand Up @@ -112,7 +113,8 @@
or UTF-8 by default."
[^String encoded & [encoding]]
(try
(URLDecoder/decode encoded (or encoding "UTF-8"))
(let [codec (URLCodec. (or encoding "UTF-8"))]
(.decode codec encoded))
(catch Exception _ nil)))

(defn form-decode
Expand Down

0 comments on commit 6b6f581

Please sign in to comment.