Skip to content

Commit 30ed025

Browse files
sogaiubakpakin
authored andcommitted
Address #284 - handle path/normalize edge case
1 parent f9c1bcf commit 30ed025

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

spork/path.janet

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@
116116
(match x
117117
[:lead what] (set lead what)
118118
"." nil
119-
".." (if (= 0 seen)
119+
".." (if (and (nil? lead) (= 0 seen))
120120
(array/push accum x)
121-
(do (-- seen) (array/pop accum)))
121+
(do
122+
(when (< 0 seen) (-- seen))
123+
(array/pop accum)))
122124
(do (++ seen) (array/push accum x))))
123125
(def ret (string (or lead "") (string/join accum ,sep)))
124126
(if (= "" ret) "." ret)))

test/suite-path.janet

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
# normalize
4545

4646
(aeq (path/posix/normalize "/abc/../") "/")
47+
(aeq (path/posix/normalize "/abc/../../def") "/def")
48+
(aeq (path/posix/normalize "/../../..") "/")
4749
(aeq (path/posix/normalize "/abc/abc") "/abc/abc")
4850
(aeq (path/posix/normalize "/abc/abc/..") "/abc")
4951
(aeq (path/posix/normalize "/abc/abc/../") "/abc/")
@@ -53,6 +55,8 @@
5355
(aeq (path/posix/normalize "//////") "/")
5456

5557
(aeq (path/win32/normalize `C:\abc\..\`) `C:\`)
58+
(aeq (path/win32/normalize `C:\abc\..\..\def`) `C:\def`)
59+
(aeq (path/win32/normalize `C:\..\..\..`) `C:\`)
5660
(aeq (path/win32/normalize `C:\abc\abc`) `C:\abc\abc`)
5761
(aeq (path/win32/normalize `C:\abc\abc\..`) `C:\abc`)
5862
(aeq (path/win32/normalize `C:\abc\abc\..\`) `C:\abc\`)

0 commit comments

Comments
 (0)