isAbsolute(r'\') should return false for Windows-style filesystem
Opened this issue · 4 comments
As per comment by @jamesderlin at google/file.dart#198 (comment) on the issue related to the file package,
The expectation is that _context.isAbsolute(path) logically implies that path includes style.drive as a prefix, which isn't true in this case. Seems like the fix for that might be more appropriate for package:path, but I'm reluctant to touch that because I'm not sure what changes are planned (or when) for v2.0 of that package.
From the documentation of isAbsolute
on Windows, returning false
for r"\"
is the correct and desired behavior.
It's doesn't do that. Tested on DartPad:
import "package:path/path.dart" as path;
void main() {
var c = path.Context(style: path.Style.windows);
print(c.isAbsolute(r'')); // false
print(c.isAbsolute(r'\')); // true ??
print(c.isAbsolute(r'\\')); // true
print(c.isAbsolute(r'a:')); // false
print(c.isAbsolute(r'a:\')); // true
}
I think the bug is in this line:
https://github.com/dart-lang/path/blob/master/lib/src/style/windows.dart#L51
if (path.length < 2 || path.codeUnitAt(1) != chars.backslash) return 1;
where it should return 0
as "root length" for a single \
input, so:
if (path.length < 2) return 0;
if (path.codeUnitAt(1) != chars.backslash) return 1;
From the documentation of
isAbsolute
on Windows, returningfalse
forr"\"
is the correct and desired behavior.
Yes. When I wrote "The expectation is that _context.isAbsolute(path)
logically implies that path
includes style.drive
as a prefix, which isn't true in this case", I meant that the implication (the boolean logic operation) wasn't true, not that _context.isAbsolute(path)
wasn't returning true
. _context.isAbsolute(r'\')
currently returns true
but should be returning false
. Sorry for not being clearer.
OK, I'm happy to close the issue.
No no, isAbsolute
is returning the wrong value, which is definitely a bug.