summaryrefslogtreecommitdiff
path: root/lib/path.js
AgeCommit message (Collapse)Author
2016-02-27path: fix win32 relative() for UNC pathsOwen Smith
win32 normalize() will output a trailing '\' for some UNC paths. trim them before processing Change by @mscdex Add basic UNC path tests to win32 relative() PR-URL: https://github.com/nodejs/node/pull/5456 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-02-27path: fix win32 relative() when "to" is a prefixOwen Smith
when the basename of "to" was a prefix of the basename of "from" win32 relative() would miss including it in the result Fixes: https://github.com/nodejs/node/issues/5447 PR-URL: https://github.com/nodejs/node/pull/5456 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-02-27path: fix verbose relative() outputBrian White
Fixes: https://github.com/nodejs/node/issues/5383 PR-URL: https://github.com/nodejs/node/pull/5389 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-02-17path: fix input type checking regressionBrian White
Before b212be08f6, input types were not checked in some path functions and the inputs were passed directly to `regexp.exec()` which implicitly converts its argument to a string. This commit both removes the type checking added in b212be08f6 and adds string coercion for those functions. PR-URL: https://github.com/nodejs/node/pull/5244 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-02-09path: performance improvements on all platformsBrian White
This commit significantly improves performance of all path functions. Optimization strategies include: * Replacing regexps with manual parsers * Avoiding unnecessary array creation (including split() + join()) * Returning earlier where possible to avoid unnecessary work * Minimize unnecessary string creation and concatenations * Combining string iterations PR-URL: https://github.com/nodejs/node/pull/5123 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-01lib: scope loop variablesRich Trott
Refactor instances in `lib` where a loop variable is redeclared in the same scope with `var`. In these cases, `let` can be used to scope the variable declarations more precisely. PR-URL: https://github.com/nodejs/node/pull/4965 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-01-13lib: fix style issues after eslint updateMichaël Zasso
With an indentation style of two spaces, it is not possible to indent multiline variable declarations by four spaces. Instead, the var keyword is used on every new line. Use const instead of var where applicable for changed lines. PR-URL: https://github.com/nodejs/io.js/pull/2286 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-11-27path: make format() consistent and more functionalNathan Woltman
Make the win32 and posix versions of path.format() consistent in when they add a directory separator between the dir and base parts of the path (always add it unless the dir part is the same as the root). Also, path.format() is now more functional in that it uses the name and ext parts of the path if the base part is left out and it uses the root part if the dir part is left out. Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/2408
2015-11-10test: fix tests that check error messagescjihrig
20285ad17755187ece16b8a5effeaa87f5407da2 changed the format of error messages throughout lib. However, the tests were not updated to reflect these changes. This commit makes those changes. PR-URL: https://github.com/nodejs/node/pull/3727 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com>
2015-11-09lib: Consistent error messages in all modulesmicnic
This commit fixes some error messages that are not consistent with some general rules which most of the error messages follow. PR-URL: https://github.com/nodejs/node/pull/3374 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-09-25path: improve posixSplitPath performanceEvan Lucas
Instead of slicing the first element off of the matches, shift and then return. This improves performance of the following path functions: - basename: 18-20% - extname: 60-70% - dirname: 18-20% - parse: 20-25% PR-URL: https://github.com/nodejs/node/pull/3034 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2015-08-17path: use '===' instead of '==' for comparisonSam Stites
Per: https://github.com/joyent/node/pull/7554 Originally submitted by @stites PR-URL: https://github.com/nodejs/node/pull/2388 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2015-08-09path: remove dead code in favor of unit testsNathan Woltman
Remove dead code paths that are created by assertions that will never trigger. They may only trigger if either the `splitDeviceRe` or `splitPathRe` regular expressions are modified. If at some point they are modified, current unit tests will catch most of the resulting errors and this commit adds extra tests to catch the remaining errors. PR-URL: https://github.com/nodejs/io.js/pull/2282 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-07-12path: assert path.join() arguments equallyPhillip Johnsen
Re-use `assertPath()` when asserting path argument types in `join()` as throughout the rest of the `path` module. This also ensures the same error message generated for posix as for win32. PR-URL: https://github.com/nodejs/io.js/pull/2159 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-07-04path: refactor for performance and consistencyNathan Woltman
Improve performance by: + Not leaking the `arguments` object! + Getting the last character of a string by index, instead of with `.substr()` or `.slice()` Improve code consistency by: + Using `[]` instead of `.charAt()` where possible + Using a function declaration instead of a var declaration + Using `.slice()` with clearer arguments + Checking if `dir` is truthy in `win32.format` (added tests for this) Improve both by: + Making the reusable `trimArray()` function + Standardizing getting certain path statistics with the new `win32StatPath()` function PR-URL: https://github.com/nodejs/io.js/pull/1778 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2015-03-19path: reduce type checking on some methodscjihrig
a465840313f548b913eb2bd8ea3d26c2ab5dcebb added strict type checking for the methods in the path module. However, dirname(), basename(), and extname() actually had some undocumented uses in the wild. This commit loosens the type checking on those methods. Fixes: https://github.com/iojs/io.js/issues/1215 PR-URL: https://github.com/iojs/io.js/pull/1216 Reviewed-By: Rod Vagg <rod@vagg.org>
2015-03-16path: add type checking for path inputscjihrig
This commit adds type checking of path inputs to exported methods in the path module. The exception is _makeLong(), which seems to explicitly support any data type. Fixes: https://github.com/iojs/io.js/issues/1139 PR-URL: https://github.com/iojs/io.js/pull/1153 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-01-31lib: reduce util.is*() usagecjihrig
Many of the util.is*() methods used to check data types simply compare against a single value or the result of typeof. This commit replaces calls to these methods with equivalent checks. This commit does not touch calls to the more complex methods (isRegExp(), isDate(), etc.). Fixes: https://github.com/iojs/io.js/issues/607 PR-URL: https://github.com/iojs/io.js/pull/647 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21lib: use const to define constantscjihrig
This commit replaces a number of var statements throughout the lib code with const statements. PR-URL: https://github.com/iojs/io.js/pull/541 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-12Remove excessive copyright/license boilerplateisaacs
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
2014-12-09path: refactor normalizeArray()Nathan Woltman
The normalizeArray() function now avoids using the slow Array#splice() method to improve performance and now also filters out empty path parts. Code that pre-filtered empty parts has been removed. PR-URL: https://github.com/joyent/node/pull/8724 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-12-08path: path.normalize no longer lower-cases drive lettersBert Belder
Fixes an omission in e24fa83.
2014-12-08Revert "path: resolve normalize drive letter to lower case"Nikolai Vavilov
This reverts commit f6e574018090ed4d63596b8a3bb614f8f48b6267. Changing drive letters to lowercase violates the principle of least surprise. Other functions that do this should get fixed too. Conflicts: lib/path.js PR-URL: https://github.com/iojs/io.js/pull/100 Reviewed-By: Bert Belder <bertbelder@gmail.com>
2014-11-22Merge remote-tracking branch 'joyent/v0.12' into v0.12Ben Noordhuis
Conflicts: Makefile deps/v8/src/base/platform/platform.h PR-URL: https://github.com/node-forward/node/pull/65 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2014-11-22lib: turn on strict modeBen Noordhuis
Turn on strict mode for the files in the lib/ directory. It helps catch bugs and can have a positive effect on performance. PR-URL: https://github.com/node-forward/node/pull/64 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-11-20path: added parse() and format() functionsRory Bradford
The parse() function splits a path and returns an object with the different elements. The format() function is the reverse of this and adds an objects corresponding path elements to make up a string. Fixes #6976. Fixes: https://github.com/joyent/node/issues/6976 PR-URL: https://github.com/joyent/node/pull/8750 Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
2014-11-20path: allow calling platform specific methodsTimothy J Fontaine
Add path.posix and path.win32 which have the specific methods like resolve and normalize so you can specifically normalize or resolve based on the target platform. PR-URL: https://github.com/joyent/node/pull/5661 Reviewed-by: Chris Dickinson <christopher.s.dickinson@gmail.com>
2014-10-25lint: fix whitespace issuesTrevor Norris
Fixes: f6e5740 "path: resolve normalize drive letter to lower case" Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-10-20path: resolve normalize drive letter to lower casedead-horse
make path.resolve work the same as path.normalize
2014-08-04path: isAbsolute() should always return booleanHerman Lee
On Windows, path.isAbsolute() returns an empty string on failed cases. This forces the return value to always be boolean. Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-08-02path: fix slice OOB in trimLucio M. Tato
Internal function trim(arr). 2nd parameter of slice() should be slice's end index (not included). Because of function normalize() (called before trim()), "start" is always zero so the bug -for now- has no effect, but its a bug waiting to happen. Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-01-21path: improve POSIX path.join() performanceJo Liss
Performance gains are ~4x (~1.5us), but still much slower than a naive approach. There is some duplicate work done between join(), normalize() and normalizeArray() so additional optimizations are possible. Note that this only improves the POSIX implementation. Thanks to @isaacs and @othiym23 for helping with this optimization. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2013-08-01src: Replace macros with util functionsisaacs
2013-07-24lib: macro-ify type checksBen Noordhuis
Increases the grep factor. Makes it easier to harmonize type checks across the code base.
2013-04-19path: add path.isAbsolute(path)Ryan Doenges
An absolute path will always open the same location regardless of your current working directory. For posix, this just means path.charAt(0) === '/', but on Windows it's a little more complicated. Fixes joyent/node#5299.
2013-03-19test: Misc Windows unit test fixesScott Blomquist
Fixes #5071, #5073. * Normalize capitalization of drive letter * Fix `exit()` typo in failure path * Ignore symlink tests (Windows) if not elevated The `test_relative_input_cwd()` test was failing on Windows when `skipSymlinks` was `true`. So we won't run it if `skipSymlinks` is `true`. When it failed, the unhandled error caused Node to die before having a chance to clean up, which resulted in two files missing in subsequent unit tests: * `test/fixtures/nested-index/one/hello.js` * `test/fixtures/nested-index/one/index.js` We should probably find a way to isolate this test from the other test (`simple/test-module-loading`) that was failing when this test poluted the disk state.
2013-02-22lintisaacs
2013-02-21path: Throw TypeError on non-string args to path.resolveisaacs
2013-02-21path: join throws TypeError on non-string argsArianit Uka
lib/path.js: - throws a TypeError on the filter if the argument is not a string. test/simple/test-path.js: - removed the test to check if non-string types are filtered. - added a test to check if path.join throws TypeError on arguments that are not strings.
2013-02-20path: Do not coerce paths to strings on Windowsisaacs
Fix #4795
2013-01-11path: make basename and extname ignore trailing slashesBert Belder
Fixes #4536
2013-01-11Revert "path: fix bugs related to paths with trailing slashes"Bert Belder
It only does the right thing on unix, and the implementation isn't great either. This reverts commit bb1c03989f8702e06072e6d9228b52661bf00ace.
2013-01-10path: fix bugs related to paths with trailing slashesAndreas Madsen
2012-12-07lintisaacs
introduced in 5b65638.
2012-11-21windows: fix normalization of UNC pathsBert Belder
2012-10-01path: add platform specific path delimiterPaul Serby
Closes #3728 Closes #4071
2012-08-27lintisaacs
2012-08-10path: small speed improvementsFelix Böhm
2012-06-21Add --no-deprecation and --trace-deprecation flagsisaacs
2012-05-15Merge remote-tracking branch 'ry/v0.6' into v0.6-mergeisaacs
Conflicts: ChangeLog deps/uv/include/uv-private/uv-unix.h deps/uv/src/unix/core.c deps/uv/src/unix/sunos.c deps/v8/src/runtime.cc doc/api/crypto.markdown lib/http.js src/node_version.h test/gc/test-http-client-timeout.js wscript