Skip to content

Commit 0680454

Browse files
committed
fixup! improve more cases
1 parent cc4d66e commit 0680454

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

benchmark/path/resolve-posix.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const bench = common.createBenchmark(main, {
66
paths: [
77
'empty',
88
'',
9+
'.',
910
['', ''].join('|'),
1011
['foo/bar', '/tmp/file/', '..', 'a/../subfile'].join('|'),
1112
['a/b/c/', '../../..'].join('|'),

benchmark/path/resolve-win32.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const bench = common.createBenchmark(main, {
66
paths: [
77
'empty',
88
'',
9+
'.',
910
['', ''].join('|'),
1011
['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'].join('|'),
1112
['c:/blah\\blah', 'd:/games', 'c:../a'].join('|'),

lib/path.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ const win32 = {
186186
}
187187
} else if (resolvedDevice.length === 0) {
188188
path = process.cwd();
189+
// Fast path for current directory
190+
if ((args.length === 0 || args.length === 1 && (args[0] === '' || args[0] === '.')) &&
191+
isPathSeparator(StringPrototypeCharCodeAt(path, 0))) {
192+
if (!isWindows) {
193+
path = StringPrototypeReplace(path, /\//g, '\\');
194+
}
195+
return path;
196+
}
189197
} else {
190198
// Windows has the concept of drive-specific current working
191199
// directories. If we've resolved a drive letter but not yet an
@@ -1171,7 +1179,7 @@ const posix = {
11711179
* @returns {string}
11721180
*/
11731181
resolve(...args) {
1174-
if (args.length === 0) {
1182+
if (args.length === 0 || args.length === 1 && (args[0] === '' || args[0] === '.')) {
11751183
const cwd = posixCwd();
11761184
if (StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH) {
11771185
return cwd;

test/parallel/test-path-resolve.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const resolveTests = [
2424
[['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'],
2525
[['c:/ignore', 'c:/some/file'], 'c:\\some\\file'],
2626
[['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'],
27+
[[], process.cwd()],
28+
[[''], process.cwd()],
2729
[['.'], process.cwd()],
2830
[['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'],
2931
[['c:/', '//'], 'c:\\'],
@@ -42,6 +44,8 @@ const resolveTests = [
4244
[[['/var/lib', '../', 'file/'], '/var/file'],
4345
[['/var/lib', '/../', 'file/'], '/file'],
4446
[['a/b/c/', '../../..'], posixyCwd],
47+
[[], posixyCwd],
48+
[[''], posixyCwd],
4549
[['.'], posixyCwd],
4650
[['/some/dir', '.', '/absolute/'], '/absolute'],
4751
[['/foo/tmp.3/', '../tmp.3/cycles/root.js'], '/foo/tmp.3/cycles/root.js'],

0 commit comments

Comments
 (0)