Skip to content
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 accepts ext as any string to remove #44773

Closed
connorjburton opened this issue Sep 24, 2022 · 5 comments · Fixed by #44774
Closed

path.basename accepts ext as any string to remove #44773

connorjburton opened this issue Sep 24, 2022 · 5 comments · Fixed by #44774
Labels
path Issues and PRs related to the path subsystem.

Comments

@connorjburton
Copy link
Contributor

connorjburton commented Sep 24, 2022

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

@Trott
Copy link
Member

Trott commented Sep 24, 2022

IIUC, this is working as designed as path.basename is modeled on the Unix tool basename which works the same way:

$ /usr/bin/basename somerandomchars chars
somerandom
$ 

@Trott
Copy link
Member

Trott commented 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
Copy link
Contributor Author

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.

@Trott
Copy link
Member

Trott commented 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.

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.

Trott added a commit to Trott/io.js that referenced this issue Sep 24, 2022
@connorjburton
Copy link
Contributor Author

No it's all good! Thank you for the quick change!

@VoltrexKeyva VoltrexKeyva added the path Issues and PRs related to the path subsystem. label Sep 26, 2022
nodejs-github-bot pushed a commit that referenced this issue Sep 27, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
juanarbol pushed a commit that referenced this issue Oct 4, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
juanarbol pushed a commit that referenced this issue Oct 4, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
juanarbol pushed a commit that referenced this issue Oct 4, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
juanarbol pushed a commit that referenced this issue Oct 4, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
juanarbol pushed a commit that referenced this issue Oct 7, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
juanarbol pushed a commit that referenced this issue Oct 10, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
danielleadams pushed a commit that referenced this issue Oct 11, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
juanarbol pushed a commit that referenced this issue Oct 11, 2022
Closes: #44773
PR-URL: #44774
Fixes: #44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this issue Jan 3, 2023
Closes: nodejs/node#44773
PR-URL: nodejs/node#44774
Fixes: nodejs/node#44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this issue Jan 3, 2023
Closes: nodejs/node#44773
PR-URL: nodejs/node#44774
Fixes: nodejs/node#44773
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
path Issues and PRs related to the path subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants