Root `Path` is incorrectly handled in ScalaJS
InversionSpaces opened this issue · 4 comments
fs2 version: 3.9.3
Reproduction example:
import fs2.io.file.Path
val p = Path("/")
println(p.normalize.absolute)
Outputs current working directory instead of /
when run in JS.
Happens because of this code:
fs2/io/js/src/main/scala/fs2/io/file/Path.scala
Lines 102 to 105 in 53f458d
Thanks for reporting! Since you've already identified the broken code, would you be interested to fix it as well? 😄
I am willing to provide a PR, but I am not quite sure how to fix that. I would just store user provided string inside Path
, but the commit that added this sep
drop is named bug fixing
, so I guess it is needed for some reason to drop that sep?
d18ddd5#diff-9fdf8bd4af13b084b80dc62144301802026204db7caabef1b0bcd64ab84daefdL74
I am not quite sure how to fix that.
It's possible that we may need to special-case this scenario.
so I guess it is needed for some reason to drop that sep
Can't remember at this point 😅 😬 you can try undoing that and see if any tests fail, and why.
Aha, probably to match JVM behavior.
$ scala
Welcome to Scala 3.3.0 (17.0.5, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> java.nio.file.Paths.get("/foo/")
val res0: java.nio.file.Path = /foo