Closed
Description
Version
18.6.0
Platform
Microsoft Windows NT 10.0.19044.0 x64
Subsystem
No response
What steps will reproduce the bug?
import assert from 'node:assert/strict';
import path from 'path';
assert.deepEqual(path.basename('somerandomchars', 'chars'), 'somerandom');
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
Should not accept a non extension string as the ext parameter.
What do you see instead?
I can use path.basename
as a generic end of string removal function.
path.basename('somerandomchars', 'chars')
removes chars
from my path
Additional information
No response
Activity
Trott commentedon Sep 24, 2022
IIUC, this is working as designed as
path.basename
is modeled on the Unix toolbasename
which works the same way:Trott commentedon Sep 24, 2022
I notice that the man page for
basename
describes the second argument as "suffix" rather than "extension" and it might be a good idea for the Node.js documentation (and code) to follow suit.connorjburton commentedon Sep 24, 2022
Understood, that makes sense to me. I will raise a PR for this change. I already have one to add more tests for similar behaviour.
path: change basename() argument from ext to suffix
Trott commentedon Sep 24, 2022
Sorry, I already opened the PR for the arg name change: #44774
But if you do incorporate it into the other PR, I'm happy to close mine.
path: change basename() argument from ext to suffix
connorjburton commentedon Sep 24, 2022
No it's all good! Thank you for the quick change!
path: change basename() argument from ext to suffix
path: change basename() argument from ext to suffix
path: change basename() argument from ext to suffix
path: change basename() argument from ext to suffix
path: change basename() argument from ext to suffix
6 remaining items