Skip to content

Commit 6b6f581

Browse files
committed
Replace the form decoder with URLCodec
- This addresses the following URLdecoding issue ring-clojure/ring#269
1 parent 94a4647 commit 6b6f581

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/ring/util/codec.clj

+12-10
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
(:import java.io.File
55
java.util.Map
66
[java.net URLEncoder URLDecoder]
7-
org.apache.commons.codec.binary.Base64))
7+
org.apache.commons.codec.binary.Base64
8+
org.apache.commons.codec.net.URLCodec))
89

910
(defn assoc-conj
1011
"Associate a key with a value in a map. If the key already exists in the map,
1112
a vector of values is associated with the key."
1213
[map key val]
1314
(assoc map key
14-
(if-let [cur (get map key)]
15-
(if (vector? cur)
16-
(conj cur val)
17-
[cur val])
18-
val)))
15+
(if-let [cur (get map key)]
16+
(if (vector? cur)
17+
(conj cur val)
18+
[cur val])
19+
val)))
1920

2021
(defn- double-escape [^String x]
2122
(.replace (.replace x "\\" "\\\\") "$" "\\$"))
@@ -58,9 +59,9 @@
5859
encoding or UTF-8 by default."
5960
[unencoded & [encoding]]
6061
(str/replace
61-
unencoded
62-
#"[^A-Za-z0-9_~.+-]+"
63-
#(double-escape (percent-encode % encoding))))
62+
unencoded
63+
#"[^A-Za-z0-9_~.+-]+"
64+
#(double-escape (percent-encode % encoding))))
6465

6566
(defn ^String url-decode
6667
"Returns the url-decoded version of the given string, using either a specified
@@ -112,7 +113,8 @@
112113
or UTF-8 by default."
113114
[^String encoded & [encoding]]
114115
(try
115-
(URLDecoder/decode encoded (or encoding "UTF-8"))
116+
(let [codec (URLCodec. (or encoding "UTF-8"))]
117+
(.decode codec encoded))
116118
(catch Exception _ nil)))
117119

118120
(defn form-decode

0 commit comments

Comments
 (0)