Skip to content

Commit

Permalink
Fix for Windows os.root() with slash error (#235)
Browse files Browse the repository at this point in the history
This also adds a unit test.

Pull request: #235
  • Loading branch information
philwalk authored Nov 15, 2023
1 parent a59b2f5 commit fd44104
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion os/src-jvm/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package object os {

def root(root: String, fileSystem: FileSystem = FileSystems.getDefault()): Path = {
val path = Path(fileSystem.getPath(root))
assert(path.root == root, s"$root is not a root path")
assert(path.root == root || path.root == root.replace('/', '\\'), s"$root is not a root path")
path
}

Expand Down
2 changes: 1 addition & 1 deletion os/src-native/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package object os {

def root(root: String, fileSystem: FileSystem = FileSystems.getDefault()): Path = {
val path = Path(fileSystem.getPath(root))
assert(path.root == root, s"$root is not a root path")
assert(path.root == root || path.root == root.replace('/', '\\'), s"$root is not a root path")
path
}

Expand Down
6 changes: 4 additions & 2 deletions os/test/src-jvm/PathTestsCustomFilesystem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ object PathTestsCustomFilesystem extends TestSuite {

val testWindows = Tests {
test("cRootPath") {
val p = os.root("C:\\") / "Users"
assert(p.toString == "C:\\Users")
val p1 = os.root("C:\\") / "Users"
assert(p1.toString == "C:\\Users")
val p2 = os.root("C:/") / "Users"
assert(p2.toString == "C:\\Users")
}
}

Expand Down

0 comments on commit fd44104

Please sign in to comment.