-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Inconsistent behavior of path.basename(path, ext) #21358
Comments
Note: the above don't come from some actual usecase that is broken by this, I used a bruteforce script that compares the old impl and the new impl outputs to find this. |
My inclination (without thinking about it too much and possibly being ignorant of some history here) would be to compare the results to that of the |
@Trott In #7519, it was decided that Also, the cases metioned here are unlikely to be met in the «good» code path and use-case, and I don't remember any reports about cases of actual breakage due to #5123 which (as I believe) initially introduced the inconsistencies metioned here. Converting to /cc @bnoordhuis |
/cc @mscdex @MylesBorins |
/cc @nodejs/collaborators, thoughts? |
@ChALkeR any updates? |
@ryzokuken I didn't get any other comments to this, I think. |
I believe this was introduced somewhere in #5123, which changed the behavior of the
ext
argument.This is observed on all supported branches and was even recently backported to 4.x.
Documentation:
https://nodejs.org/api/path.html#path_path_basename_path_ext
Observe the input and try to predict the output:
There are more, but all the inconsistencies with the previous behavior involve at least one of those:
path
ends with/
,ext
includes/
,ext
equals to the actual resolved basename (i.e.path.endsWith('/' + ext)
).More specifically, the following check covers all the cases inconsistent behavior to my knowledge:
path.endsWith('/') || ext.includes('/') || path.endsWith('/' + ext)
(note that it also includes cases of consistent behavior).
Reminder: before #5123, this was how
ext
behave:I.e. it just sliced off the suffix (after doing everything else).
The text was updated successfully, but these errors were encountered: