Skip to content

Commit fd44104

Browse files
authored
Fix for Windows os.root() with slash error (#235)
This also adds a unit test. Pull request: #235
1 parent a59b2f5 commit fd44104

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

os/src-jvm/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package object os {
1515

1616
def root(root: String, fileSystem: FileSystem = FileSystems.getDefault()): Path = {
1717
val path = Path(fileSystem.getPath(root))
18-
assert(path.root == root, s"$root is not a root path")
18+
assert(path.root == root || path.root == root.replace('/', '\\'), s"$root is not a root path")
1919
path
2020
}
2121

os/src-native/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package object os {
1212

1313
def root(root: String, fileSystem: FileSystem = FileSystems.getDefault()): Path = {
1414
val path = Path(fileSystem.getPath(root))
15-
assert(path.root == root, s"$root is not a root path")
15+
assert(path.root == root || path.root == root.replace('/', '\\'), s"$root is not a root path")
1616
path
1717
}
1818

os/test/src-jvm/PathTestsCustomFilesystem.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ object PathTestsCustomFilesystem extends TestSuite {
226226

227227
val testWindows = Tests {
228228
test("cRootPath") {
229-
val p = os.root("C:\\") / "Users"
230-
assert(p.toString == "C:\\Users")
229+
val p1 = os.root("C:\\") / "Users"
230+
assert(p1.toString == "C:\\Users")
231+
val p2 = os.root("C:/") / "Users"
232+
assert(p2.toString == "C:\\Users")
231233
}
232234
}
233235

0 commit comments

Comments
 (0)