File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
Sources/FoundationEssentials/String
Tests/FoundationEssentialsTests Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,12 @@ extension String {
63
63
// This is a trailing slash. Ignore it.
64
64
let beforeLastSlash = self [ startIndex..< lastSlash] . lastIndex { $0 == " / " }
65
65
if let beforeLastSlash {
66
- return String ( self [ startIndex..< beforeLastSlash] )
66
+ if beforeLastSlash == startIndex {
67
+ // Only the first slash remains, return a bare slash.
68
+ return " / "
69
+ } else {
70
+ return String ( self [ startIndex..< beforeLastSlash] )
71
+ }
67
72
} else {
68
73
// No other slash. Return empty string.
69
74
return " "
Original file line number Diff line number Diff line change @@ -255,6 +255,7 @@ class DataIOTests : XCTestCase {
255
255
XCTAssertEqual ( " / " . deletingLastPathComponent ( ) , " / " )
256
256
XCTAssertEqual ( " q " . deletingLastPathComponent ( ) , " " )
257
257
XCTAssertEqual ( " /aaa " . deletingLastPathComponent ( ) , " / " )
258
+ XCTAssertEqual ( " /aaa/ " . deletingLastPathComponent ( ) , " / " )
258
259
XCTAssertEqual ( " /a/b/c/ " . deletingLastPathComponent ( ) , " /a/b " )
259
260
XCTAssertEqual ( " hello " . deletingLastPathComponent ( ) , " " )
260
261
XCTAssertEqual ( " hello/ " . deletingLastPathComponent ( ) , " " )
You can’t perform that action at this time.
0 commit comments