Skip to content

Commit 181ab3c

Browse files
authored
Fix issue with relative MS-windows paths (#704)
Hi, can you please consider a fix for not dropping the first character of paths on MS-windows. It fixes #703. This issue was introduced with a fix in #688 where the redundant first char should only be dropped from absolute paths. I've added a test for the same. Thanks Co-authored-by: ikappaki <[email protected]>
1 parent d7329a2 commit 181ab3c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
* Fix issue with `case` evaluating all of its clauses expressions (#699).
9+
* Fix issue with relative paths dropping their first character on MS-Windows (#703).
910

1011
## [v0.1.0a2]
1112
### Added

src/basilisp/io.lpy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
(as-path [f]
3434
(if (contains? #{"file" ""} (.-scheme f))
3535
(let [path (.-path f)]
36-
(if (= sys/platform "win32")
37-
;; On MS-Windows, extracting the path from the URL
36+
(if (and (= sys/platform "win32") (os.path/isabs path))
37+
;; On MS-Windows, extracting an absolute path from the URL
3838
;; incorrectly adds a leading `/', .e.g. /C:\xyz.
3939
(pathlib/Path (subs path 1))
4040

tests/basilisp/test_io.lpy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,18 @@
162162
(testing "cannot write read-only file"
163163
(with-open [f (python/open path ** :mode "r")]
164164
(is (thrown? basilisp.lang.exception/ExceptionInfo
165-
(spit f "some content")))))))
165+
(spit f "some content")))))
166+
167+
(testing "relative path"
168+
(let [[fd filename] (tempfile/mkstemp ** :dir "." :prefix "test-rel-path-")]
169+
(try
170+
(let [filename-rel (os.path/relpath filename ".")]
171+
(with-open [f (python/open filename-rel ** :mode "w")]
172+
(spit f "hello rel"))
173+
(is (= "hello rel" (slurp filename-rel))))
174+
(finally
175+
(os/close fd)
176+
(os/unlink filename)))))))
166177

167178
(testing "http requests"
168179
(let [url (str "http://localhost:" *http-port* "/writer-http-req.txt")]

0 commit comments

Comments
 (0)