-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
fix require.resolve
not considering paths .
and ..
relative
#56735
fix require.resolve
not considering paths .
and ..
relative
#56735
Conversation
Review requested:
|
9ffc34a
to
7e988e5
Compare
require.resolve
paths option not treating ..
as relativerequire.resolve
not considering paths .
and ..
relative
do all of these added tests fail on main, or only a subset of them? |
The |
c8424cc
to
02cbc98
Compare
ah ok, so this is specifically a bug with |
sorry, my bad, updated 🫡 |
Yes, as far as I can tell that's the case, this for example: node/test/parallel/test-require-dot.js Lines 11 to 12 in 869ea33
does indicate that . is correctly treated as a relative path in standard require calls
|
May I suggest to not include The commit message needs to be shorter, e.g. |
02cbc98
to
7a97c0b
Compare
Sorry I added them by mistake when I squashed fixup commits, I've already removed them
Sorry the contributing MD made me thing I was supposed to add that 😓
Yes I did notice the linting error, hopefully my newer title is ok? |
To be clear, you can 100% do that if you prefer to do it – what's important is for the commit landing on |
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: nodejs#47000
7a97c0b
to
562e1c6
Compare
Got it 🙂 Maybe I can open a quick PR to add a note to clarify that here? node/doc/contributing/pull-requests.md Lines 183 to 191 in 869ea33
WDYT? (I'm guessing that |
Co-authored-by: Yagiz Nizipli <yagiz@nizipli.com>
This comment was marked as outdated.
This comment was marked as outdated.
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.
lgtm
/** | ||
* Checks if a path is relative | ||
* @param {string} path the target path | ||
* @returns {boolean} true if the path is relative, false otherwise | ||
*/ | ||
function isRelative(path) { | ||
if (StringPrototypeCharCodeAt(path, 0) !== CHAR_DOT) { return false; } | ||
|
||
return path.length === 1 || path === '..' || | ||
StringPrototypeStartsWith(path, './') || | ||
StringPrototypeStartsWith(path, '../') || | ||
((isWindows && StringPrototypeStartsWith(path, '.\\')) || | ||
StringPrototypeStartsWith(path, '..\\')); | ||
} |
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.
🎉
Landed in 7119303 |
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: #47000 PR-URL: #56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: #47000 PR-URL: #56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: nodejs#47000 PR-URL: nodejs#56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: #47000 PR-URL: #56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Fixes: #47000