File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 3838 (map (partial format " %%%02X" ))
3939 (str/join ))))
4040
41- (defn- parse-bytes [encoded-bytes]
42- (->> (re-seq #"%[A-Za-z0-9]{2}" encoded-bytes)
43- (map #(subs % 1 ))
44- (map #(.byteValue (Integer/valueOf % 16 )))
45- (byte-array )))
41+ (defn- parse-bytes ^bytes [encoded-bytes]
42+ (let [encoded-len (count encoded-bytes)
43+ bs (byte-array (/ encoded-len 3 ))]
44+ (loop [encoded-index 1 , byte-index 0 ]
45+ (if (< encoded-index encoded-len)
46+ (let [encoded-byte (subs encoded-bytes encoded-index (+ encoded-index 2 ))
47+ b (.byteValue (Integer/valueOf encoded-byte 16 ))]
48+ (aset bs byte-index b)
49+ (recur (+ encoded-index 3 ) (inc byte-index)))
50+ bs))))
4651
4752(defn percent-decode
4853 " Decode every percent-encoded character in the given string using the
5358 (str/replace encoded
5459 #"(?:%[A-Za-z0-9]{2})+"
5560 (fn [chars]
56- (-> ^bytes (parse-bytes chars)
61+ (-> (parse-bytes chars)
5762 (String. encoding)
5863 (fix-string-replace-bug ))))))
5964
You can’t perform that action at this time.
0 commit comments