Skip to content

Commit 99ca792

Browse files
Antondomashnevkylef
authored andcommitted
fix(join): Combining paths . and ../foo/baz returns correct result (#36)
1 parent 891a3fe commit 99ca792

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# PathKit Changelog
22

3+
## Master
4+
5+
### Bug Fixes
6+
7+
* Appending to (.) slice started with (..) will return correct path.
8+
[Antondomashnev](https://github.com/Antondomashnev)
9+
10+
311
## 0.8.0
412

513
### Enhancements

Sources/PathKit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,8 @@ internal func +(lhs: String, rhs: String) -> Path {
765765
rSlice = rSlice.filter { $0 != "." }.fullSlice
766766

767767
// Eats up trailing components of the left and leading ".." of the right side
768-
while lSlice.last != ".." && rSlice.first == ".." {
769-
if (lSlice.count > 1 || lSlice.first != Path.separator) && !lSlice.isEmpty {
768+
while lSlice.last != ".." && !lSlice.isEmpty && rSlice.first == ".." {
769+
if lSlice.count > 1 || lSlice.first != Path.separator {
770770
// A leading "/" is never popped
771771
lSlice.removeLast()
772772
}

Tests/PathKitTests/PathKitSpec.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ describe("PathKit") {
480480
try expect(Path("a")) == "./." + "a"
481481
try expect(Path(".")) == "." + "."
482482
try expect(Path(".")) == "./." + "./."
483+
try expect(Path("../a")) == "." + "./../a"
484+
try expect(Path("../a")) == "." + "../a"
483485

484486
// Appending (to) '..'
485487
try expect(Path(".")) == "a" + ".."

0 commit comments

Comments
 (0)