File tree 2 files changed +8
-11
lines changed
test/clojure/test_clojure/java
2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change 19
19
StringReader ByteArrayInputStream
20
20
BufferedInputStream BufferedOutputStream
21
21
CharArrayReader Closeable)
22
- (java.net URI URL MalformedURLException Socket)))
22
+ (java.net URI URL MalformedURLException Socket URLDecoder URLEncoder )))
23
23
24
24
(def
25
25
^{:doc " Type object for a Java primitive byte array."
37
37
(^{:tag java.io.File, :added " 1.2" } as-file [x] " Coerce argument to a file." )
38
38
(^{:tag java.net.URL, :added " 1.2" } as-url [x] " Coerce argument to a URL." ))
39
39
40
+ (defn- escaped-utf8-urlstring->str [s]
41
+ (-> (clojure.string/replace s " +" (URLEncoder/encode " +" " UTF-8" ))
42
+ (URLDecoder/decode " UTF-8" )))
43
+
40
44
(extend-protocol Coercions
41
45
nil
42
46
(as-file [_] nil )
54
58
(as-url [u] u)
55
59
(as-file [u]
56
60
(if (= " file" (.getProtocol u))
57
- (as-file
58
- (clojure.string/replace
59
- (.replace (.getFile u) \/ File/separatorChar)
60
- #"%.."
61
- (fn [escape]
62
- (-> escape
63
- (.substring 1 3 )
64
- (Integer/parseInt 16 )
65
- (char )
66
- (str )))))
61
+ (as-file (escaped-utf8-urlstring->str
62
+ (.replace (.getFile u) \/ File/separatorChar)))
67
63
(throw (IllegalArgumentException. (str " Not a file: " u)))))
68
64
69
65
URI
Original file line number Diff line number Diff line change 126
126
(File. " bar+baz" ) (URL. " file:bar+baz" )
127
127
(File. " bar baz qux" ) (URL. " file:bar%20baz%20qux" )
128
128
(File. " quux" ) (URI. " file:quux" )
129
+ (File. " abcíd/foo.txt" ) (URL. " file:abc%c3%add/foo.txt" )
129
130
nil nil ))
130
131
131
132
(deftest test-resources-with-spaces
You can’t perform that action at this time.
0 commit comments