[Git][java-team/ring-codec-clojure][upstream] New upstream version 1.1.2
Louis-Philippe Véronneau
gitlab at salsa.debian.org
Wed Dec 30 19:03:34 GMT 2020
Louis-Philippe Véronneau pushed to branch upstream at Debian Java Maintainers / ring-codec-clojure
Commits:
96d622e8 by Louis-Philippe Véronneau at 2020-12-21T17:58:19-05:00
New upstream version 1.1.2
- - - - -
6 changed files:
- + CONTRIBUTING.md
- + LICENSE
- README.md
- project.clj
- src/ring/util/codec.clj
- test/ring/util/test/codec.clj
Changes:
=====================================
CONTRIBUTING.md
=====================================
@@ -0,0 +1,30 @@
+# Contributing Guidelines
+
+**Do** follow [the seven rules of a great Git commit message][1].
+
+**Do** follow [the Clojure Style Guide][2].
+
+**Do** include tests for your change when appropriate.
+
+**Do** ensure that the CI checks pass.
+
+**Do** squash the commits in your PR to remove corrections
+irrelevant to the code history, once the PR has been reviewed.
+
+**Do** feel free to pester the project maintainers about the PR if it
+hasn't been responded to. Sometimes notifications can be missed.
+
+**Don't** overuse vertical whitespace; avoid multiple sequential blank
+lines.
+
+**Don't** include more than one feature or fix in a single PR.
+
+**Don't** include changes unrelated to the purpose of the PR. This
+includes changing the project version number, adding lines to the
+`.gitignore` file, or changing the indentation or formatting.
+
+**Don't** open a new PR if changes are requested. Just push to the
+same branch and the PR will be updated.
+
+[1]: https://chris.beams.io/posts/git-commit/#seven-rules
+[2]: https://github.com/bbatsov/clojure-style-guide
=====================================
LICENSE
=====================================
@@ -0,0 +1,23 @@
+Copyright (c) 2009-2010 Mark McGranaghan
+Copyright (c) 2009-2018 James Reeves
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
=====================================
README.md
=====================================
@@ -9,7 +9,7 @@ web applications.
To install, add the following to your project `:dependencies`:
- [ring/ring-codec "1.0.1"]
+ [ring/ring-codec "1.1.2"]
## Documentation
@@ -17,6 +17,6 @@ To install, add the following to your project `:dependencies`:
## License
-Copyright © 2016 James Reeves
+Copyright © 2019 James Reeves
Distributed under the MIT License, the same as Ring.
=====================================
project.clj
=====================================
@@ -1,18 +1,19 @@
-(defproject ring/ring-codec "1.0.1"
+(defproject ring/ring-codec "1.1.2"
:description "Library for encoding and decoding data"
:url "https://github.com/ring-clojure/ring-codec"
:license {:name "The MIT License"
:url "http://opensource.org/licenses/MIT"}
- :dependencies [[org.clojure/clojure "1.3.0"]
- [commons-codec "1.6"]]
- :plugins [[lein-codox "0.9.5"]]
+ :dependencies [[org.clojure/clojure "1.5.1"]
+ [commons-codec "1.11"]]
+ :plugins [[lein-codox "0.10.3"]]
:codox
{:output-path "codox"
:source-uri "http://github.com/ring-clojure/ring-codec/blob/{version}/{filepath}#L{line}"}
- :aliases {"test-all" ["with-profile" "default:+1.4:+1.5:+1.6:+1.7:+1.8" "test"]}
+ :aliases {"test-all" ["with-profile" "default:+1.6:+1.7:+1.8:+1.9:+1.10" "test"]}
:profiles
- {:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
- :1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]}
- :1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]}
- :1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
- :1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}})
+ {:dev {:dependencies [[criterium "0.4.4"]]}
+ :1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]}
+ :1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
+ :1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
+ :1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
+ :1.10 {:dependencies [[org.clojure/clojure "1.10.0"]]}})
=====================================
src/ring/util/codec.clj
=====================================
@@ -31,10 +31,12 @@
(defn percent-encode
"Percent-encode every character in the given string using either the specified
encoding, or UTF-8 by default."
- [^String unencoded & [^String encoding]]
- (->> (.getBytes unencoded (or encoding "UTF-8"))
- (map (partial format "%%%02X"))
- (str/join)))
+ ([unencoded]
+ (percent-encode unencoded "UTF-8"))
+ ([^String unencoded ^String encoding]
+ (->> (.getBytes unencoded encoding)
+ (map (partial format "%%%02X"))
+ (str/join))))
(defn- parse-bytes [encoded-bytes]
(->> (re-seq #"%[A-Za-z0-9]{2}" encoded-bytes)
@@ -45,28 +47,34 @@
(defn percent-decode
"Decode every percent-encoded character in the given string using the
specified encoding, or UTF-8 by default."
- [^String encoded & [^String encoding]]
- (str/replace encoded
- #"(?:%[A-Za-z0-9]{2})+"
- (fn [chars]
- (-> ^bytes (parse-bytes chars)
- (String. (or encoding "UTF-8"))
- (fix-string-replace-bug)))))
+ ([encoded]
+ (percent-decode encoded "UTF-8"))
+ ([^String encoded ^String encoding]
+ (str/replace encoded
+ #"(?:%[A-Za-z0-9]{2})+"
+ (fn [chars]
+ (-> ^bytes (parse-bytes chars)
+ (String. encoding)
+ (fix-string-replace-bug))))))
(defn url-encode
"Returns the url-encoded version of the given string, using either a specified
encoding or UTF-8 by default."
- [unencoded & [encoding]]
- (str/replace
+ ([unencoded]
+ (url-encode unencoded "UTF-8"))
+ ([unencoded encoding]
+ (str/replace
unencoded
#"[^A-Za-z0-9_~.+-]+"
- #(double-escape (percent-encode % encoding))))
+ #(double-escape (percent-encode % encoding)))))
(defn ^String url-decode
"Returns the url-decoded version of the given string, using either a specified
encoding or UTF-8 by default. If the encoding is invalid, nil is returned."
- [encoded & [encoding]]
- (percent-decode encoded encoding))
+ ([encoded]
+ (url-decode encoded "UTF-8"))
+ ([encoded encoding]
+ (percent-decode encoded encoding)))
(defn base64-encode
"Encode an array of bytes into a base64 encoded string."
@@ -83,49 +91,58 @@
(extend-protocol FormEncodeable
String
- (form-encode* [unencoded encoding]
+ (form-encode* [^String unencoded ^String encoding]
(URLEncoder/encode unencoded encoding))
Map
(form-encode* [params encoding]
(letfn [(encode [x] (form-encode* x encoding))
- (encode-param [[k v]] (str (encode (name k)) "=" (encode v)))]
+ (encode-param [k v] (str (encode (name k)) "=" (encode v)))]
(->> params
(mapcat
(fn [[k v]]
- (if (or (seq? v) (sequential? v) )
- (map #(encode-param [k %]) v)
- [(encode-param [k v])])))
+ (cond
+ (sequential? v) (map #(encode-param k %) v)
+ (set? v) (sort (map #(encode-param k %) v))
+ :else (list (encode-param k v)))))
(str/join "&"))))
Object
(form-encode* [x encoding]
- (form-encode* (str x) encoding)))
+ (form-encode* (str x) encoding))
+ nil
+ (form-encode* [x encoding] ""))
(defn form-encode
"Encode the supplied value into www-form-urlencoded format, often used in
URL query strings and POST request bodies, using the specified encoding.
If the encoding is not specified, it defaults to UTF-8"
- [x & [encoding]]
- (form-encode* x (or encoding "UTF-8")))
+ ([x]
+ (form-encode x "UTF-8"))
+ ([x encoding]
+ (form-encode* x encoding)))
(defn form-decode-str
"Decode the supplied www-form-urlencoded string using the specified encoding,
or UTF-8 by default."
- [^String encoded & [encoding]]
- (try
- (URLDecoder/decode encoded (or encoding "UTF-8"))
- (catch Exception _ nil)))
+ ([encoded]
+ (form-decode-str encoded "UTF-8"))
+ ([^String encoded ^String encoding]
+ (try
+ (URLDecoder/decode encoded encoding)
+ (catch Exception _ nil))))
(defn form-decode
"Decode the supplied www-form-urlencoded string using the specified encoding,
or UTF-8 by default. If the encoded value is a string, a string is returned.
If the encoded value is a map of parameters, a map is returned."
- [^String encoded & [encoding]]
- (if-not (.contains encoded "=")
- (form-decode-str encoded encoding)
- (reduce
- (fn [m param]
- (if-let [[k v] (str/split param #"=" 2)]
- (assoc-conj m (form-decode-str k encoding) (form-decode-str v encoding))
- m))
- {}
- (str/split encoded #"&"))))
+ ([encoded]
+ (form-decode encoded "UTF-8"))
+ ([^String encoded encoding]
+ (if-not (.contains encoded "=")
+ (form-decode-str encoded encoding)
+ (reduce
+ (fn [m param]
+ (if-let [[k v] (str/split param #"=" 2)]
+ (assoc-conj m (form-decode-str k encoding) (form-decode-str (or v "") encoding))
+ m))
+ {}
+ (str/split encoded #"&")))))
=====================================
test/ring/util/test/codec.clj
=====================================
@@ -39,11 +39,16 @@
(is (= (form-encode "foo/bar" "UTF-16") "foo%FE%FF%00%2Fbar")))
(testing "maps"
(are [x y] (= (form-encode x) y)
- {"a" "b"} "a=b"
- {:a "b"} "a=b"
- {"a" 1} "a=1"
+ {"a" "b"} "a=b"
+ {:a "b"} "a=b"
+ {"a" 1} "a=1"
+ {"a" nil} "a="
{"a" "b" "c" "d"} "a=b&c=d"
- {"a" "b c"} "a=b+c")
+ {"a" "b c"} "a=b+c"
+ {"a" ["b" "c"]} "a=b&a=c"
+ {"a" ["c" "b"]} "a=c&a=b"
+ {"a" (seq [1 2])} "a=1&a=2"
+ {"a" #{"c" "b"}} "a=b&a=c")
(is (= (form-encode {"a" "foo/bar"} "UTF-16") "a=foo%FE%FF%00%2Fbar"))))
(deftest test-form-decode-str
@@ -57,6 +62,9 @@
"a=b&c=d" {"a" "b" "c" "d"}
"foo+bar" "foo bar"
"a=b+c" {"a" "b c"}
- "a=b%2Fc" {"a" "b/c"})
+ "a=b%2Fc" {"a" "b/c"}
+ "a=b&c" {"a" "b" "c" ""}
+ "a=&b=c" {"a" "" "b" "c"}
+ "a&b=c" {"a" "" "b" "c"})
(is (= (form-decode "a=foo%FE%FF%00%2Fbar" "UTF-16")
{"a" "foo/bar"})))
View it on GitLab: https://salsa.debian.org/java-team/ring-codec-clojure/-/commit/96d622e85ddd6fa2d61a6c9267ce86a152884f85
--
View it on GitLab: https://salsa.debian.org/java-team/ring-codec-clojure/-/commit/96d622e85ddd6fa2d61a6c9267ce86a152884f85
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20201230/9c3e513a/attachment.html>
More information about the pkg-java-commits
mailing list