From 6b6f581efc82f78053a9f8c1d0a690a8aec5c485 Mon Sep 17 00:00:00 2001 From: iku000888 Date: Wed, 7 Dec 2016 13:58:02 +0900 Subject: [PATCH] Replace the form decoder with URLCodec - This addresses the following URLdecoding issue https://github.com/ring-clojure/ring/issues/269 --- src/ring/util/codec.clj | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ring/util/codec.clj b/src/ring/util/codec.clj index de57108..128bdb0 100644 --- a/src/ring/util/codec.clj +++ b/src/ring/util/codec.clj @@ -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 "\\" "\\\\") "$" "\\$")) @@ -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 @@ -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