diff --git a/Sources/Files.swift b/Sources/Files.swift index d8e0368..7ecb5a3 100644 --- a/Sources/Files.swift +++ b/Sources/Files.swift @@ -204,6 +204,8 @@ public final class Storage { } private func validatePath() throws { + path = path.removingPrefix("./") + switch LocationType.kind { case .file: guard !path.isEmpty else { @@ -230,6 +232,10 @@ public final class Storage { path.replaceSubrange(.. Folder { - let folderPath = path + folderPath.removingPrefix("/") + let folderPath = path + folderPath.removingPrefix("/").removingPrefix("./") let storage = try Storage(path: folderPath, fileManager: fileManager) return Folder(storage: storage) } diff --git a/Tests/FilesTests/FilesTests.swift b/Tests/FilesTests/FilesTests.swift index 7076461..578204c 100644 --- a/Tests/FilesTests/FilesTests.swift +++ b/Tests/FilesTests/FilesTests.swift @@ -658,6 +658,32 @@ class FilesTests: XCTestCase { XCTAssertEqual(Folder.current, folder) } } + + func testAccessingCurrentFolderWithRelativePath() { + performTest { + let folderA = try Folder(path: "./") + let folderB = try Folder.current.subfolder(at: "./") + XCTAssertEqual(folderA, folderB) + XCTAssertEqual(folderA, .current) + } + } + + func testAccessingFileInCurrentFolderWithRelativePath() { + performTest { + let fileA = try Folder.current.createFile(named: "Test") + let fileB = try File(path: "./Test") + XCTAssertEqual(fileA, fileB) + } + } + + func testAccessingParentFolderWithRelativePath() { + performTest { + let folderA = try Folder(path: "../") + let folderB = try Folder.current.subfolder(at: "../") + XCTAssertEqual(folderA, folderB) + XCTAssertEqual(folderA, Folder.current.parent) + } + } func testNameExcludingExtensionWithLongFileName() { performTest { @@ -865,6 +891,9 @@ class FilesTests: XCTestCase { ("testMovingFolderHiddenContents", testMovingFolderHiddenContents), ("testAccessingHomeFolder", testAccessingHomeFolder), ("testAccessingCurrentWorkingDirectory", testAccessingCurrentWorkingDirectory), + ("testAccessingCurrentFolderWithRelativePath", testAccessingCurrentFolderWithRelativePath), + ("testAccessingFileInCurrentFolderWithRelativePath", testAccessingFileInCurrentFolderWithRelativePath), + ("testAccessingParentFolderWithRelativePath", testAccessingParentFolderWithRelativePath), ("testNameExcludingExtensionWithLongFileName", testNameExcludingExtensionWithLongFileName), ("testRelativePaths", testRelativePaths), ("testRelativePathIsAbsolutePathForNonParent", testRelativePathIsAbsolutePathForNonParent),