-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Handle root path correctly #3354
Changes from 1 commit
cd297d2
e0d836f
b35d234
87bee7d
5c5e5ff
f0a4373
6b2d8a3
0e2495d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ package file | |
import fs2.io.internal.facade | ||
|
||
import scala.annotation.tailrec | ||
import scala.collection.IndexedSeqView | ||
|
||
final case class Path private[file] (override val toString: String) extends PathApi { | ||
|
||
|
@@ -99,20 +98,16 @@ final case class Path private[file] (override val toString: String) extends Path | |
object Path extends PathCompanionApi { | ||
private[file] val sep = facade.path.sep | ||
|
||
private[file] def dropTrailingSep(path: String): String = { | ||
/* | ||
* NOTE: It seems like scala js does not rewrite this to a loop? | ||
* Call stack limit is reached if there are too many separators. | ||
*/ | ||
@tailrec | ||
def drop(view: IndexedSeqView[Char]): IndexedSeqView[Char] = | ||
// Drop separator only if there is something else left | ||
if (view.endsWith(sep) && view.length > sep.length) | ||
drop(view.dropRight(sep.length)) | ||
else view | ||
|
||
drop(path.view).mkString | ||
} | ||
/* | ||
* NOTE: It seems like scala js does not rewrite this to a loop? | ||
* Call stack limit is reached if there are too many separators. | ||
*/ | ||
@tailrec | ||
private[file] def dropTrailingSep(path: String): String = | ||
// Drop separator only if there is something else left | ||
if (path.endsWith(sep) && path.length > sep.length) | ||
dropTrailingSep(path.dropRight(sep.length)) | ||
else path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does actually 🤔 Here's what it's compiled to: $c_Lfs2_io_file_Path$.prototype.dropTrailingSep__T__T = (function(path) {
while (true) {
if ($f_T__endsWith__T__Z($n(path), this.Lfs2_io_file_Path$__f_sep)) {
var this$1 = $n(path);
var this$2 = $n(this.Lfs2_io_file_Path$__f_sep);
var $$x2 = (this$1.length > this$2.length)
} else {
var $$x2 = false
};
if ($$x2) {
var $$x1 = $m_sc_StringOps$();
var x = path;
var this$4 = $n(this.Lfs2_io_file_Path$__f_sep);
path = $n($$x1).dropRight$extension__T__I__T(x, this$4.length)
} else {
break
}
};
return path
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This passes for me. How were you getting the failure? assertEquals(Path("/".repeat(Int.MaxValue/8)), Path("/")) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange, I wrote this comment when I used |
||
|
||
/** This method drops trailing separators to match | ||
* `java.nio.file.Path.get` behaviour. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like to Officially:tm: support Windows 🤮 but its path can look like
C:\
which I think would get re-written toC:
. I have no idea if that's good or bad 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing some tests on Powershell
Thus, it seems they are not equivalent.
IMHO, it is best to avoid this specific
Path
modification, also it may be good to add a unit test verifying it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used node API exclusively