0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

97 Commits

Author SHA1 Message Date
Brian White
dfaa9c9055
path: fix basename() regressions
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-18 02:12:28 -04:00
Rich Trott
a56da51a38 benchmark,test,lib: remove extra spaces
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-05-11 23:18:16 -07:00
Brian White
3072546feb path: fix win32.isAbsolute() inconsistency
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-04-04 14:45:22 -07:00
Brian White
08085c49b6 path: assert inputs are strings
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-17 23:20:12 -04:00
Rich Trott
9de9a08587 path: refactor path.format() repeated code
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-16 10:19:41 -07:00
Evan Lucas
3d3b45ae95 path: fix normalize for absolutes
Fixes a regression introduced by
b212be08f6.

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-03-07 14:48:49 -06:00
Owen Smith
f296a7f16f path: fix path.relative() for prefixes at root
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-29 20:10:04 +01:00
Zheng Chaoping
4717ea9186 path: fix win32 parse()
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>
2016-02-29 19:39:56 +01:00
Owen Smith
e326950498 path: fix win32 relative() for UNC paths
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-27 17:30:44 +01:00
Owen Smith
b33879d9e2 path: fix win32 relative() when "to" is a prefix
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-27 17:29:29 +01:00
Brian White
3a331b66f8 path: fix verbose relative() output
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-27 14:42:33 +01:00
Brian White
9209bf6d43 path: fix input type checking regression
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-17 14:18:43 -05:00
Brian White
b212be08f6 path: performance improvements on all platforms
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-09 20:35:46 -08:00
Rich Trott
089d84f8fa lib: scope loop variables
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-02-01 09:28:38 -08:00
Michaël Zasso
7ce0e04f44 lib: fix style issues after eslint update
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>
2016-01-13 23:16:05 +01:00
Nathan Woltman
d1000b4137 path: make format() consistent and more functional
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-27 11:53:33 +00:00
cjihrig
2c33819370 test: fix tests that check error messages
20285ad177 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-10 07:12:33 +01:00
micnic
20285ad177 lib: Consistent error messages in all modules
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-11-09 20:08:36 +01:00
Evan Lucas
b50e89e01f path: improve posixSplitPath performance
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-09-25 08:28:26 -05:00
Sam Stites
1a3b295d0f path: use '===' instead of '==' for comparison
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-17 20:47:41 +02:00
Nathan Woltman
2db57bdecc path: remove dead code in favor of unit tests
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-08-09 12:29:01 +02:00
Phillip Johnsen
2ba84606a6 path: assert path.join() arguments equally
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-12 01:05:05 +02:00
Nathan Woltman
bca53dce76 path: refactor for performance and consistency
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-07-04 13:24:59 +02:00
cjihrig
8de78e470d path: reduce type checking on some methods
a465840313 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-19 21:11:12 -04:00
cjihrig
eb995d6822 path: add type checking for path inputs
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-03-16 12:49:21 -04:00
cjihrig
6ac8bdc0ab lib: reduce util.is*() usage
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-31 23:47:29 -05:00
cjihrig
804e7aa9ab lib: use const to define constants
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-21 16:21:31 -05:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
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.
2015-01-12 15:30:28 -08:00
Nathan Woltman
50d7401244 path: refactor normalizeArray()
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-09 17:57:09 +01:00
Bert Belder
b4d6203b38 path: path.normalize no longer lower-cases drive letters
Fixes an omission in e24fa83.
2014-12-08 21:34:17 +01:00
Nikolai Vavilov
e24fa83e69 Revert "path: resolve normalize drive letter to lower case"
This reverts commit f6e5740180.

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-12-08 17:35:52 +01:00
Ben Noordhuis
fcbbc7a050 Merge remote-tracking branch 'joyent/v0.12' into v0.12
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-22 17:55:59 +01:00
Ben Noordhuis
21130c7d6f lib: turn on strict mode
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-22 17:23:30 +01:00
Rory Bradford
2d17193f20 path: added parse() and format() functions
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-20 16:21:11 -08:00
Timothy J Fontaine
6a90a06002 path: allow calling platform specific methods
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-11-20 16:10:55 -08:00
Trevor Norris
6a68d64629 lint: fix whitespace issues
Fixes: f6e5740 "path: resolve normalize drive letter to lower case"
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-10-25 14:27:23 -07:00
dead-horse
f6e5740180 path: resolve normalize drive letter to lower case
make path.resolve work the same as path.normalize
2014-10-20 20:48:00 +02:00
Herman Lee
20229d6896 path: isAbsolute() should always return boolean
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-04 13:39:12 -07:00
Lucio M. Tato
37c2a52833 path: fix slice OOB in trim
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-08-02 00:19:20 -07:00
Jo Liss
b9bec2031e path: improve POSIX path.join() performance
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>
2014-01-21 17:00:56 -08:00
isaacs
22c68fdc1d src: Replace macros with util functions 2013-08-01 15:08:01 -07:00
Ben Noordhuis
0330bdf519 lib: macro-ify type checks
Increases the grep factor. Makes it easier to harmonize type checks
across the code base.
2013-07-24 21:49:35 +02:00
Ryan Doenges
9026675061 path: add path.isAbsolute(path)
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-04-19 10:15:22 -07:00
Scott Blomquist
a05f973f82 test: Misc Windows unit test fixes
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-03-19 09:38:11 -07:00
isaacs
74c08403d8 lint 2013-02-22 16:30:27 -08:00
isaacs
089ec58613 path: Throw TypeError on non-string args to path.resolve 2013-02-21 15:18:44 -08:00
Arianit Uka
055110dab0 path: join throws TypeError on non-string args
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-21 11:50:47 -08:00
isaacs
bbcb8b3ae0 path: Do not coerce paths to strings on Windows
Fix #4795
2013-02-20 14:04:30 -08:00
Bert Belder
6a91eab097 path: make basename and extname ignore trailing slashes
Fixes #4536
2013-01-11 18:50:09 +01:00
Bert Belder
7be27240b5 Revert "path: fix bugs related to paths with trailing slashes"
It only does the right thing on unix, and the implementation
isn't great either.

This reverts commit bb1c03989f.
2013-01-11 16:19:21 +01:00