summaryrefslogtreecommitdiff
path: root/lib/path.js
AgeCommit message (Collapse)Author
2019-11-09path: replace var with let in lib/path.jspeze
PR-URL: https://github.com/nodejs/node/pull/30260 Refs: https://github.com/nodejs/code-and-learn/issues/97 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
2019-10-05lib: introduce no-mixed-operators eslint rule to libZYSzys
PR-URL: https://github.com/nodejs/node/pull/29834 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-08-05path: improve normalization performanceBrian White
PR-URL: https://github.com/nodejs/node/pull/28948 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
2019-07-14path: move branch to the correct locationRuben Bridgewater
This code branch only makes sense when i === length. Otherwise it'll already be handled. PR-URL: https://github.com/nodejs/node/pull/28556 Fixes: https://github.com/nodejs/node/issues/28549 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
2019-07-14path: using .relative() should not return a trailing slashRuben Bridgewater
Resolving a path against root with `path.relative()` should not include a trailing slash. Fixes: https://github.com/nodejs/node/issues/28549 PR-URL: https://github.com/nodejs/node/pull/28556 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
2019-04-18path: simplify normalizeStringRuben Bridgewater
This improves the `path.normalize()` and `path.resolve()` performance a tiny bit. One statement could never be truthy, another check could be simplified and `code` is now monomorphic. PR-URL: https://github.com/nodejs/node/pull/27240 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-04-03path: refactor for less indentationRuben Bridgewater
This just switches the statements in a way that it reduces the overall indentation. The function has a very deep indentation in general and this should improve the readability. PR-URL: https://github.com/nodejs/node/pull/26917 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2019-03-30benchmark,lib: change var to constRuben Bridgewater
Refs: https://github.com/nodejs/node/pull/26679 PR-URL: https://github.com/nodejs/node/pull/26915 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
2019-03-29path: remove dead codeRuben Bridgewater
A couple of code parts could not be reached due to resolving the path in the beginning. That "normalizes" the path in a way that some code branches became obsolete. PR-URL: https://github.com/nodejs/node/pull/26916 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-28path: fix win32 parse regressionRuben Bridgewater
This fixes the parse function for single character input that are not a path separator. PR-URL: https://github.com/nodejs/node/pull/26912 Fixes: https://github.com/nodejs/node/issues/26911 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-01path: refactor code for clarityRuben Bridgewater
This moves a condition inside of a for loop which can only be triggered at the very end of the for loop outside of the loop. That way the for loop itself is much simpler and easier to understand and the code itself is less indented which should increase the readability. It also refactors some `var` to `let` and `const`. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-01path: refactor for less indentationRuben Bridgewater
This moves the `if (len === 1)` case to the top of the function. That way it is possible to reduce the indentation level due to returning early in that case. On top of that the following was done: 1) For clarity refactored for loops which were meant to count up a variable into a while loop. 2) Used template strings instead of string concat. 3) Consolidating nested if statements. 4) Using tenary expressions if applicable when assigning variables to reduce the code overhead. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-01path: simplify code and remove obsolete checksRuben Bridgewater
Either `end` is `-1` or `startPart` is not `0`. Therefore it's possible to move the conditions in a way that we eliminate a few code branches. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-01path: refactor logic for to reduce code branchesRuben Bridgewater
This refactoring makes sure some code branches will not be hit if they do not have to be reached. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-01path: minor refactoringRuben Bridgewater
1) Consolidate nested if statements if possible `if (foo) { if bar () { /* do stuff */ } }`) to reduce indentation depth. 2) Remove obsolete else cases to reduce indentation. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-01path: refactor more path code for simplicityRuben Bridgewater
1) Consolidate format to a single function. 2) Move some code that can only be reached in some code branches that was formerly executed in all cases. 3) Explicitly check for the string length of zero instead of converting the string to a boolean. 4) Consolidate nested if statements if possible e.g., if (foo) { if (bar) { /* do stuff */ } } to reduce indentation depth. 5) Simplify checks by removing extra length checks when comparing two strings. 6) Use object shorthand notation where possible. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-01path: more small refactoringsRuben Bridgewater
1) Refactor for loops to while loops that were only meant to count up a variable. 2) Refactor some `var` statements to `let` / `const`. 3) Simplify return conditions. 4) Use template strings where possible instead of concat. 5) Use ternary expressions for variable assignments instead of if / else. 6) Use the object shorthand notation for the function declarations. 7) Consolidate if else case where possible. 8) Remove double line breaks. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-01path: minor refactoringRuben Bridgewater
1) This uses some ternary expressions instead of if else to assign some variables. 2) Use template strings instead of concat. 3) Use the object shortand notation. 4) Some var to let / const. 5) Removed some double line breaks. 6) Less brackets around statements if not necessary. PR-URL: https://github.com/nodejs/node/pull/25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-12-06path: replace assertPath() with validatorcjihrig
The path module's assertPath() does exactly what the validateString() validator does, so this commit updates path to use validateString() instead. A couple drive by updates to validateString() outside of assertPath() are also included. PR-URL: https://github.com/nodejs/node/pull/24840 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2018-10-30lib: remove useless cwd in posix.resolveZYSzys
PR-URL: https://github.com/nodejs/node/pull/23902 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-09-16path: remove unnecessary if statementWilliam Chargin
There is an `if`-statement in `normalizeString` (a helper function for `path.normalize`) whose `else`-branch is never taken. This patch removes it. PR-URL: https://github.com/nodejs/node/pull/22273 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-03-25lib: always show ERR_INVALID_ARG_TYPE received partRuben Bridgewater
This makes a effort to make sure all of these errors will actually also show the received input. On top of that it refactors a few tests for better maintainability. It will also change the returned type to always be a simple typeof instead of special handling null. PR-URL: https://github.com/nodejs/node/pull/19445 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-03-23path: fix regression in posix.normalizeMichaël Zasso
Fixes a regression introduced in [1]. The posix version of normalize should not treat backslash as a path separator. [1] https://github.com/nodejs/node/commit/4ae320f2 PR-URL: https://github.com/nodejs/node/pull/19520 Fixes: https://github.com/nodejs/node/issues/19519 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-03-14path: remove redundant functionSergey Golovin
PR-URL: https://github.com/nodejs/node/pull/19237 Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-03-05lib: port errors to new systemMichaël Zasso
This is a first batch of updates that touches non-underscored modules in lib. PR-URL: https://github.com/nodejs/node/pull/19034 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-02-17path: replace duplicate conditions by functionsSergey Golovin
It will also remove useless "code" variables by inlining path.charCodeAt. PR-URL: https://github.com/nodejs/node/pull/18693 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-02-12path: replace "magic" numbers by readable constantsSergey Golovin
PR-URL: https://github.com/nodejs/node/pull/18654 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2018-01-11path: fix path.normalize for relative pathsWeijia Wang
After slicing, the `lastSegmentLength` should be calculated again, instead of assigning value `j`. PR-URL: https://github.com/nodejs/node/pull/17974 Fixes: https://github.com/nodejs/node/issues/17928 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-11-22benchmark,path: remove unused variables薛定谔的猫
PR-URL: https://github.com/nodejs/node/pull/15789 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2017-11-16path: remove obsolete commentRich Trott
Remove commented-out code that is leftover from a refactoring. PR-URL: https://github.com/nodejs/node/pull/17023 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Lance Ball <lball@redhat.com>
2017-10-19tools: enable additional eslint rulesAnatoli Papirovski
Enable additional rules that node either already adheres to or it makes sense to do so going forward: for-direction, accessor-pairs, no-lonely-if and symbol-description. Fix all instances of no-lonely-if in lib & test and disable accessor-pairs in test-util-inspect. PR-URL: https://github.com/nodejs/node/pull/16243 Refs: https://eslint.org/docs/rules/for-direction Refs: https://eslint.org/docs/rules/accessor-pairs Refs: https://eslint.org/docs/rules/no-lonely-if Refs: https://eslint.org/docs/rules/symbol-description Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-10-02doc: fix unassigned deprecation codeJames M Snell
Forgot to assign the deprecation code when landing 1f8d527e94ad97e7db14d18406fe0e12983358cb PR-URL: https://github.com/nodejs/node/pull/15741 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-10-02path: deprecate internal _makeLong, replaceJames M Snell
Replace the internal `path._makeLong()` with a public `path.toLongUNCPath()` method. Add documentation. PR-URL: https://github.com/nodejs/node/pull/14956 Ref: https://github.com/standard-things/esm/issues/66 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-09-26path: fix normalize paths ending with two dotsMichaël Zasso
Fixes: https://github.com/nodejs/security/issues/147 PR-URL: https://github.com/nodejs-private/node-private/pull/94 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Doug Wilson <doug@somethingdoug.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-08-30path: fix normalize on directories with two dotsMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/14107 Fixes: https://github.com/nodejs/node/issues/14105 Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-07-30path: fix win32 volume-relative pathsTimothy Gu
`path.resolve()` and `path.join()` are left alone in this commit due to the lack of clear semantics. PR-URL: https://github.com/nodejs/node/pull/14440 Fixes: https://github.com/nodejs/node/issues/14405 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-07-26path: remove unnecessary string copiesTobias Nießen
As the length of `path` is known at this point, there is no point in making an exact copy using `slice`. PR-URL: https://github.com/nodejs/node/pull/14438 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe>
2017-07-03path: fix incorrect use of ERR_INVALID_ARG_TYPETobias Nießen
PR-URL: https://github.com/nodejs/node/pull/14011 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-06-06path: use internal/errors.jsSebastian Van Sande
PR-URL: https://github.com/nodejs/node/pull/11319 Ref: https://github.com/nodejs/node/issues/11273 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-03-10meta: restore original copyright headerJames M Snell
A prior io.js era commit inappropriately removed the original copyright statements from the source. This restores those in any files still remaining from that edit. Ref: https://github.com/nodejs/TSC/issues/174 Ref: https://github.com/nodejs/node/pull/10599 PR-URL: https://github.com/nodejs/node/pull/10155 Note: This PR was required, reviewed-by and approved by the Node.js Foundation Legal Committee and the TSC. There is no `Approved-By:` meta data.
2016-09-24path: fallback to process cwd when resolving drive cwdJason Ginchereau
The `path.resolve()` function when given just a drive letter such as "C:" tries to get a drive-specific CWD, but that isn't available in cases when the process is not launched via cmd.exe and the process CWD has not been explicitly set on that drive. This change adds a fallback to the process CWD, if the process CWD happens to be on the resolved drive letter. If the process CWD is on another drive, then a drive-specific CWD cannot be resolved and defaults to the drive's root as before. Based on experimentation, the fixed behavior matches that of other similar path resolution implementations on Windows I checked: .NET's `System.IO.Path.GetFullPath()` and Python's `os.path.abspath()`. In the automated path test cases the issue doesn't occur when the tests are run normally from cmd.exe. But it did cause an assertion when running the tests from PowerShell, that is fixed by this change. PR-URL: https://github.com/nodejs/node/pull/8541 Fixes: https://github.com/nodejs/node/issues/7215 Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-09-20path: fix path.relative UNC path resultJason Ginchereau
When the result of a path.relative() is an absolute UNC path, it should include the leading backslashes. Fixes: https://github.com/nodejs/node/issues/8444 PR-URL: https://github.com/nodejs/node/pull/8523 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
2016-05-18path: fix basename() regressionsBrian White
This commit fixes a regression in basename() for the case when a supplied extension name completely matches the resulting basename. Fixes: https://github.com/nodejs/node/issues/6587 PR-URL: https://github.com/nodejs/node/pull/6590 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-05-11benchmark,test,lib: remove extra spacesRich Trott
In preparation for stricter linting, remove extra spaces. PR-URL: https://github.com/nodejs/node/pull/6645 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-04-04path: fix win32.isAbsolute() inconsistencyBrian White
This commit fixes an inconsistency in absolute path checking compared to the absolute path detection used by the other path.win32 functions. Fixes: https://github.com/nodejs/node/issues/6027 PR-URL: https://github.com/nodejs/node/pull/6028 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-17path: assert inputs are stringsBrian White
This commit makes input type checking consistent across all path functions. PR-URL: https://github.com/nodejs/node/pull/5348 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-03-16path: refactor path.format() repeated codeRich Trott
PR-URL: https://github.com/nodejs/node/pull/5673 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-03-07path: fix normalize for absolutesEvan Lucas
Fixes a regression introduced by b212be08f62a48656c5befd8be0a82d691ea66e4. path.normalize(''/a/b/c/../../../x/y/z'') should return '/x/y/z'. Fixes: https://github.com/nodejs/node/issues/5585 PR-URL: https://github.com/nodejs/node/pull/5589 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-02-29path: fix path.relative() for prefixes at rootOwen Smith
Fixes #5485 PR-URL: https://github.com/nodejs/node/pull/5490 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-02-29path: fix win32 parse()Zheng Chaoping
Fix path.win32.parse("/foo/bar") retuns `{root: '' ...}`(v5.7.0), but not `{root: '/' ...}`(v5.6.0). PR-URL: https://github.com/nodejs/node/pull/5484 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Roman Reiss <me@silverwind.io>