summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Smith-Mannschott <bsmith.occs@gmail.com>2010-07-25 10:45:12 +0200
committerStuart Halloway <stu@thinkrelevance.com>2010-07-27 17:04:00 -0400
commita2c95ef1bf6e34a455b469ac9ff18ddff7e9cef7 (patch)
tree85aa0ec8ed30759d2c0636ed4f6432bd3318678d
parent973ea840118fa1deca8eb92c81130ae61525a74a (diff)
♯413 parse-args defaults in-enc and out-enc to UTF-8, as required by sh
Previously parse-args was defaulting in-enc and out-enc to the platform default charset. This contradicted the intent of sh, which is to default to UTF-8 on all platforms. This appears not to have been noticed because the unit tests were still testing for the previous behavior of defaulting to platform encoding. (As it turns out the old behavior of using Charset/defaultCharset would have been wrong on Mac OS X since it claims "Mac Roman" here despite the fact that Mac OS X uses UTF-8 throughout, including in Terminal.app, shell and file system.) Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r--src/clj/clojure/java/shell.clj2
-rw-r--r--test/clojure/test_clojure/java/shell.clj10
2 files changed, 7 insertions, 5 deletions
diff --git a/src/clj/clojure/java/shell.clj b/src/clj/clojure/java/shell.clj
index fa553671..004629df 100644
--- a/src/clj/clojure/java/shell.clj
+++ b/src/clj/clojure/java/shell.clj
@@ -44,7 +44,7 @@ collecting its stdout"}
(defn- parse-args
[args]
- (let [default-encoding (.name (Charset/defaultCharset))
+ (let [default-encoding "UTF-8" ;; see sh doc string
default-opts {:out-enc default-encoding :in-enc default-encoding :dir *sh-dir* :env *sh-env*}
[cmd opts] (split-with string? args)]
[cmd (merge default-opts (apply hash-map opts))]))
diff --git a/test/clojure/test_clojure/java/shell.clj b/test/clojure/test_clojure/java/shell.clj
index d3db7db0..56e3ff04 100644
--- a/test/clojure/test_clojure/java/shell.clj
+++ b/test/clojure/test_clojure/java/shell.clj
@@ -12,13 +12,15 @@
(:import (java.io File)))
(def platform-enc (.name (java.nio.charset.Charset/defaultCharset)))
+(def default-enc "UTF-8")
(deftest test-parse-args
(are [x y] (= x y)
- [[] {:in-enc platform-enc :out-enc platform-enc :dir nil :env nil}] (#'sh/parse-args [])
- [["ls"] {:in-enc platform-enc :out-enc platform-enc :dir nil :env nil}] (#'sh/parse-args ["ls"])
- [["ls" "-l"] {:in-enc platform-enc :out-enc platform-enc :dir nil :env nil}] (#'sh/parse-args ["ls" "-l"])
- [["ls"] {:in-enc platform-enc :out-enc "ISO-8859-1" :dir nil :env nil}] (#'sh/parse-args ["ls" :out-enc "ISO-8859-1"])))
+ [[] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args [])
+ [["ls"] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args ["ls"])
+ [["ls" "-l"] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args ["ls" "-l"])
+ [["ls"] {:in-enc default-enc :out-enc "ISO-8859-1" :dir nil :env nil}] (#'sh/parse-args ["ls" :out-enc "ISO-8859-1"])
+ [[] {:in-enc platform-enc :out-enc platform-enc :dir nil :env nil}] (#'sh/parse-args [:in-enc platform-enc :out-enc platform-enc])))
(deftest test-with-sh-dir
(are [x y] (= x y)