-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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.basename matches ext
parameter case-sensitively on case-insensitive filesystems
#13727
Comments
One thing worth mentioning: The But I agree, it would seem reasonable to make this change on Windows. |
Also, a case-insensitive check (e.g. the need to call |
Micro benchmark: const ext = '.ps1';
const name = 'D:\\code\\node\\vcbuild.ps1';
console.time('without');
for (let i = 0; i < 1E8; ++i) {
basename(name, ext);
}
console.timeEnd('without');
console.time('with');
for (let i = 0; i < 1E8; ++i) {
basename(name, ext.toLowerCase());
}
console.timeEnd('with'); Output:
But since the code actually does char by char |
@refack You would also need to Additionally, we can't assume ASCII on Windows/MacOS (and I'm not sure checking for and bailing on non-ASCII characters would avoid a regression). |
Yep. |
Also, it's technically possible (from what I briefly read) to make Windows case-sensitive (with regard to filesystem operations), although I don't know how common that is (NTFS itself already supports case sensitivity). |
That is true 🤔 (NTFS is case sensitive, it's the kernel that isn't, Ref: https://technet.microsoft.com/en-us/library/cc725747(v=ws.11).aspx) |
This looks (to me, at least) like something we're not likely to change. Thanks for the issue. You're totally right that this is worth being intentional about. I think this should be closed, but if anyone disagrees, please re-open (or leave a comment if GitHub doesn't let you re-open it). |
(By the way, if we do add a third argument, I'd prefer it be an |
(PR welcome on that third argument, although no guarantee it won't be met with "this should be done in userland". I would be OK with it, though.) |
On systems with case-insensitive filesystems, path.basename nevertheless matches its
ext
parameter case-sensitively, which enables subtle bugs like istanbuljs/spawn-wrap#56 and is inconsistent with the behavior of other APIs like fs.existsSync that observe the case-sensitivity of the filesystem:path.basename's behavior is, however, consistent with the basename program on the Unix-like systems I've tested, which also matches an extension case-sensitively, even on a case-insensitive filesystem (like my macOS system). Nevertheless, it feels like a footgun, as some developers will expect the behavior to be consistent across the fs and path APIs.
By comparison:
Note that 7c731ec added the comment "// TODO: make this comparison case-insensitive on windows? " to path.basename back in 2011. Then #5123 removed it as part of a broader rewrite (although there's no evidence that the latter change was intended to resolve the TODO one way or the other).
I could argue this either way, so I would understand intentionally not fixing it. But it does seem like a footgun, given the aforementioned bug (for which I've submitted a fix that does the extension stripping in a separate String.replace operation). At the very least, I thought it worth an issue, so even if you decide not to change the behavior, that decision will be documented somewhere.
The text was updated successfully, but these errors were encountered: