Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
path: fix basename() regressions#6590
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -15,6 +15,23 @@ assert.equal(path.basename('/basename.ext'), 'basename.ext'); | ||
| assert.equal(path.basename('basename.ext'), 'basename.ext'); | ||
| assert.equal(path.basename('basename.ext/'), 'basename.ext'); | ||
| assert.equal(path.basename('basename.ext//'), 'basename.ext'); | ||
| assert.equal(path.basename('aaa/bbb', '/bbb'), 'bbb'); | ||
| assert.equal(path.basename('aaa/bbb', 'a/bbb'), 'bbb'); | ||
| assert.equal(path.basename('aaa/bbb', 'bbb'), 'bbb'); | ||
| assert.equal(path.basename('aaa/bbb//', 'bbb'), 'bbb'); | ||
| assert.equal(path.basename('aaa/bbb', 'bb'), 'b'); | ||
| assert.equal(path.basename('aaa/bbb', 'b'), 'bb'); | ||
| assert.equal(path.basename('/aaa/bbb', '/bbb'), 'bbb'); | ||
| assert.equal(path.basename('/aaa/bbb', 'a/bbb'), 'bbb'); | ||
| assert.equal(path.basename('/aaa/bbb', 'bbb'), 'bbb'); | ||
| assert.equal(path.basename('/aaa/bbb//', 'bbb'), 'bbb'); | ||
| assert.equal(path.basename('/aaa/bbb', 'bb'), 'b'); | ||
| assert.equal(path.basename('/aaa/bbb', 'b'), 'bb'); | ||
| assert.equal(path.basename('/aaa/bbb'), 'bbb'); | ||
Contributor 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. Just wondering, why were these tests removed? ContributorAuthor 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.
| ||
| assert.equal(path.basename('/aaa/'), 'aaa'); | ||
| assert.equal(path.basename('/aaa/b'), 'b'); | ||
| assert.equal(path.basename('/a/b'), 'b'); | ||
| assert.equal(path.basename('//a'), 'a'); | ||
| // On Windows a backslash acts as a path separator. | ||
| assert.equal(path.win32.basename('\\dir\\basename.ext'), 'basename.ext'); | ||
| @@ -23,11 +40,12 @@ assert.equal(path.win32.basename('basename.ext'), 'basename.ext'); | ||
| assert.equal(path.win32.basename('basename.ext\\'), 'basename.ext'); | ||
| assert.equal(path.win32.basename('basename.ext\\\\'), 'basename.ext'); | ||
| assert.equal(path.win32.basename('foo'), 'foo'); | ||
| assert.throws(path.win32.basename.bind(null, null), TypeError); | ||
| assert.throws(path.win32.basename.bind(null, true), TypeError); | ||
| assert.throws(path.win32.basename.bind(null, 1), TypeError); | ||
| assert.throws(path.win32.basename.bind(null), TypeError); | ||
| assert.throws(path.win32.basename.bind(null, {}), TypeError); | ||
| assert.equal(path.win32.basename('aaa\\bbb', '\\bbb'), 'bbb'); | ||
| assert.equal(path.win32.basename('aaa\\bbb', 'a\\bbb'), 'bbb'); | ||
| assert.equal(path.win32.basename('aaa\\bbb', 'bbb'), 'bbb'); | ||
| assert.equal(path.win32.basename('aaa\\bbb\\\\\\\\', 'bbb'), 'bbb'); | ||
| assert.equal(path.win32.basename('aaa\\bbb', 'bb'), 'b'); | ||
| assert.equal(path.win32.basename('aaa\\bbb', 'b'), 'bb'); | ||
| // On unix a backslash is just treated as any other character. | ||
| assert.equal(path.posix.basename('\\dir\\basename.ext'), '\\dir\\basename.ext'); | ||
| @@ -36,11 +54,6 @@ assert.equal(path.posix.basename('basename.ext'), 'basename.ext'); | ||
| assert.equal(path.posix.basename('basename.ext\\'), 'basename.ext\\'); | ||
| assert.equal(path.posix.basename('basename.ext\\\\'), 'basename.ext\\\\'); | ||
| assert.equal(path.posix.basename('foo'), 'foo'); | ||
| assert.throws(path.posix.basename.bind(null, null), TypeError); | ||
| assert.throws(path.posix.basename.bind(null, true), TypeError); | ||
| assert.throws(path.posix.basename.bind(null, 1), TypeError); | ||
| assert.throws(path.posix.basename.bind(null), TypeError); | ||
| assert.throws(path.posix.basename.bind(null, {}), TypeError); | ||
| // POSIX filenames may include control characters | ||
| // c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html | ||
| @@ -60,11 +73,6 @@ assert.equal(path.posix.dirname(''), '.'); | ||
| assert.equal(path.posix.dirname('/'), '/'); | ||
| assert.equal(path.posix.dirname('////'), '/'); | ||
| assert.equal(path.posix.dirname('foo'), '.'); | ||
| assert.throws(path.posix.dirname.bind(null, null), TypeError); | ||
| assert.throws(path.posix.dirname.bind(null, true), TypeError); | ||
| assert.throws(path.posix.dirname.bind(null, 1), TypeError); | ||
| assert.throws(path.posix.dirname.bind(null), TypeError); | ||
| assert.throws(path.posix.dirname.bind(null, {}), TypeError); | ||
| assert.equal(path.win32.dirname('c:\\'), 'c:\\'); | ||
| assert.equal(path.win32.dirname('c:\\foo'), 'c:\\'); | ||
| @@ -100,11 +108,6 @@ assert.equal(path.win32.dirname(''), '.'); | ||
| assert.equal(path.win32.dirname('/'), '/'); | ||
| assert.equal(path.win32.dirname('////'), '/'); | ||
| assert.equal(path.win32.dirname('foo'), '.'); | ||
| assert.throws(path.win32.dirname.bind(null, null), TypeError); | ||
| assert.throws(path.win32.dirname.bind(null, true), TypeError); | ||
| assert.throws(path.win32.dirname.bind(null, 1), TypeError); | ||
| assert.throws(path.win32.dirname.bind(null), TypeError); | ||
| assert.throws(path.win32.dirname.bind(null, {}), TypeError); | ||
| // path.extname tests | ||
| @@ -183,11 +186,6 @@ assert.equal(path.win32.extname('file\\'), ''); | ||
| assert.equal(path.win32.extname('file\\\\'), ''); | ||
| assert.equal(path.win32.extname('file.\\'), '.'); | ||
| assert.equal(path.win32.extname('file.\\\\'), '.'); | ||
| assert.throws(path.win32.extname.bind(null, null), TypeError); | ||
| assert.throws(path.win32.extname.bind(null, true), TypeError); | ||
| assert.throws(path.win32.extname.bind(null, 1), TypeError); | ||
| assert.throws(path.win32.extname.bind(null), TypeError); | ||
| assert.throws(path.win32.extname.bind(null, {}), TypeError); | ||
| // On *nix, backslash is a valid name component like any other character. | ||
| assert.equal(path.posix.extname('.\\'), ''); | ||
| @@ -198,11 +196,6 @@ assert.equal(path.posix.extname('file\\'), ''); | ||
| assert.equal(path.posix.extname('file\\\\'), ''); | ||
| assert.equal(path.posix.extname('file.\\'), '.\\'); | ||
| assert.equal(path.posix.extname('file.\\\\'), '.\\\\'); | ||
| assert.throws(path.posix.extname.bind(null, null), TypeError); | ||
| assert.throws(path.posix.extname.bind(null, true), TypeError); | ||
| assert.throws(path.posix.extname.bind(null, 1), TypeError); | ||
| assert.throws(path.posix.extname.bind(null), TypeError); | ||
| assert.throws(path.posix.extname.bind(null, {}), TypeError); | ||
| // path.join tests | ||
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.
maybe add a few tests for absolute paths with this case?
Uh oh!
There was an error while loading. Please reload this page.
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've now added absolute versions of these tests, is that what you meant?
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 was thinking maybe something more like
path.basename('/aaa/bbb')since we have seen regressions for absolute vs relative paths. They may already be there thoughThere 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.
Ok, I've added that and a couple more.
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.
@evanlucas does this LGTY now?