-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
path: fix win32 volume-relative paths #14440
Changes from all commits
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 |
---|---|---|
|
@@ -72,6 +72,16 @@ assert.strictEqual(path.win32.basename('aaa\\bbb', 'bbb'), 'bbb'); | |
assert.strictEqual(path.win32.basename('aaa\\bbb\\\\\\\\', 'bbb'), 'bbb'); | ||
assert.strictEqual(path.win32.basename('aaa\\bbb', 'bb'), 'b'); | ||
assert.strictEqual(path.win32.basename('aaa\\bbb', 'b'), 'bb'); | ||
assert.strictEqual(path.win32.basename('C:'), ''); | ||
assert.strictEqual(path.win32.basename('C:.'), '.'); | ||
assert.strictEqual(path.win32.basename('C:\\'), ''); | ||
assert.strictEqual(path.win32.basename('C:\\dir\\base.ext'), 'base.ext'); | ||
assert.strictEqual(path.win32.basename('C:\\basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('C:basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('C:basename.ext\\'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('C:basename.ext\\\\'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('C:foo'), 'foo'); | ||
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. Again, a test for NTFS alternate streams would be nice: |
||
assert.strictEqual(path.win32.basename('file:stream'), 'file:stream'); | ||
|
||
// On unix a backslash is just treated as any other character. | ||
assert.strictEqual(path.posix.basename('\\dir\\basename.ext'), | ||
|
@@ -120,6 +130,8 @@ assert.strictEqual(path.win32.dirname('c:foo\\'), 'c:'); | |
assert.strictEqual(path.win32.dirname('c:foo\\bar'), 'c:foo'); | ||
assert.strictEqual(path.win32.dirname('c:foo\\bar\\'), 'c:foo'); | ||
assert.strictEqual(path.win32.dirname('c:foo\\bar\\baz'), 'c:foo\\bar'); | ||
assert.strictEqual(path.win32.dirname('file:stream'), '.'); | ||
assert.strictEqual(path.win32.dirname('dir\\file:stream'), 'dir'); | ||
assert.strictEqual(path.win32.dirname('\\\\unc\\share'), | ||
'\\\\unc\\share'); | ||
assert.strictEqual(path.win32.dirname('\\\\unc\\share\\foo'), | ||
|
@@ -187,6 +199,7 @@ assert.strictEqual(path.win32.dirname('foo'), '.'); | |
['file./', '.'], | ||
['file.//', '.'], | ||
].forEach((test) => { | ||
const expected = test[1]; | ||
[path.posix.extname, path.win32.extname].forEach((extname) => { | ||
let input = test[0]; | ||
let os; | ||
|
@@ -197,12 +210,19 @@ assert.strictEqual(path.win32.dirname('foo'), '.'); | |
os = 'posix'; | ||
} | ||
const actual = extname(input); | ||
const expected = test[1]; | ||
const message = `path.${os}.extname(${JSON.stringify(input)})\n expect=${ | ||
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`; | ||
if (actual !== expected) | ||
failures.push(`\n${message}`); | ||
}); | ||
{ | ||
const input = `C:${test[0].replace(slashRE, '\\')}`; | ||
const actual = path.win32.extname(input); | ||
const message = `path.win32.extname(${JSON.stringify(input)})\n expect=${ | ||
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`; | ||
if (actual !== expected) | ||
failures.push(`\n${message}`); | ||
} | ||
}); | ||
assert.strictEqual(failures.length, 0, failures.join('')); | ||
|
||
|
@@ -406,6 +426,12 @@ assert.strictEqual(path.win32.normalize('a//b//.'), 'a\\b'); | |
assert.strictEqual(path.win32.normalize('//server/share/dir/file.ext'), | ||
'\\\\server\\share\\dir\\file.ext'); | ||
assert.strictEqual(path.win32.normalize('/a/b/c/../../../x/y/z'), '\\x\\y\\z'); | ||
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. Optional:Could you parameterize this part like the others are: [[a,b]].forEach(([tested, expected]) => ... (not the scope of this PR but still would be nice) 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. I'd rather leave that to a dedicated PR, as there are many other tests that do not use this pattern in the file. |
||
assert.strictEqual(path.win32.normalize('C:'), 'C:.'); | ||
assert.strictEqual(path.win32.normalize('C:..\\abc'), 'C:..\\abc'); | ||
assert.strictEqual(path.win32.normalize('C:..\\..\\abc\\..\\def'), | ||
'C:..\\..\\def'); | ||
assert.strictEqual(path.win32.normalize('C:\\.'), 'C:\\'); | ||
assert.strictEqual(path.win32.normalize('file:stream'), 'file:stream'); | ||
|
||
assert.strictEqual(path.posix.normalize('./fixtures///b/../b/c.js'), | ||
'fixtures/b/c.js'); | ||
|
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.
Could you add tests for NTFS alterate streams? e.g.
['cd:foo', '']
. Not just to testroot
, but also the other properties used incheckParseFormat
.