Skip to content

Commit 6bccff4

Browse files
[source-files] Properly convert file path to URI
1 parent 8266fc5 commit 6bccff4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## master (unreleased)
44

5+
* [#316](https://github.com/clojure-emacs/orchard/pull/316): Java: properly convert file path that contains spaces or backslashes to URI.
6+
57
## 0.30.0 (2025-01-10)
68

79
* [#310](https://github.com/clojure-emacs/orchard/pull/310): Java: add functions for downloading 3rd-party Java sources from Maven.

src/orchard/java/source_files.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@
8080
(defn- combine-archive-url ^URL [^File archive, relative-filename]
8181
;; Even though the JDK stores sources in a zip archive, we still use this
8282
;; function that prefixes the URL with jar:. This is fine.
83-
(io/as-url (format "jar:file:%s!/%s"
84-
;; Replace backslashes with forward slashes. Needed on
85-
;; Windows. Forward slashes would still work there, while
86-
;; backslashes are forbidden in URLs.
87-
(string/replace archive "\\" "/")
88-
relative-filename)))
83+
(try
84+
(let [uri-str (str (.toURI archive))]
85+
(when (string/starts-with? uri-str "file:")
86+
(io/as-url (format "jar:%s!/%s" uri-str relative-filename))))
87+
;; Exceptions might happen when creating an URL, protect users from them.
88+
(catch java.net.MalformedURLException _)))
8989

9090
(defn- locate-source-url-in-jdk-sources
9191
"Try to find the source file for `klass` in sources included with JDK."

0 commit comments

Comments
 (0)