GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc,test: empty strings in path module · nodejs/node@65963ec

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • path.markdown
  • test/parallel
    • test-path-zero-length-strings.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/path.markdown‎

Copy file name to clipboardExpand all lines: doc/api/path.markdown
+20-1Lines changed: 20 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Example:
2222
// returns
2323
'/foo/bar/baz/asdf'
2424

25+
*Note:* If the path string passed as argument is a zero-length string then `'.'`
26+
will be returned, which represents the current working directory.
27+
2528
## path.join([path1][, path2][, ...])
2629

2730
Join all arguments together and normalize the resulting path.
@@ -39,6 +42,11 @@ Example:
3942
// throws exception
4043
TypeError: Arguments to path.join must be strings
4144

45+
*Note:* If the arguments to `join` have zero-length strings, unlike other path
46+
module functions, they will be ignored. If the joined path string is a
47+
zero-length string then `'.'` will be returned, which represents the
48+
current working directory.
49+
4250
## path.resolve([from ...], to)
4351

4452
Resolves `to` to an absolute path.
@@ -78,6 +86,9 @@ Examples:
7886
// if currently in /home/myself/iojs, it returns
7987
'/home/myself/iojs/wwwroot/static_files/gif/image.gif'
8088

89+
*Note:* If the arguments to `resolve` have zero-length strings then the current
90+
working directory will be used instead of them.
91+
8192
## path.isAbsolute(path)
8293

8394
Determines whether `path` is an absolute path. An absolute path will always
@@ -94,9 +105,13 @@ Windows examples:
94105

95106
path.isAbsolute('//server') // true
96107
path.isAbsolute('C:/foo/..') // true
97-
path.isAbsolute('bar\\baz') // false
108+
path.isAbsolute('bar\\baz') // false
98109
path.isAbsolute('.') // false
99110

111+
*Note:* If the path string passed as parameter is a zero-length string, unlike
112+
other path module functions, it will be used as-is and `false` will be
113+
returned.
114+
100115
## path.relative(from, to)
101116

102117
Solve the relative path from `from` to `to`.
@@ -117,6 +132,10 @@ Examples:
117132
// returns
118133
'../../impl/bbb'
119134

135+
*Note:* If the arguments to `relative` have zero-length strings then the current
136+
working directory will be used instead of the zero-length strings. If
137+
both the paths are the same then a zero-length string will be returned.
138+
120139
## path.dirname(p)
121140

122141
Return the directory name of a path. Similar to the Unix `dirname` command.
Collapse file

‎test/parallel/test-path-zero-length-strings.js‎

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
// These testcases are specific to one uncommon behaviour in path module. Few
4+
// of the functions in path module, treat '' strings as current working
5+
// directory. This test makes sure that the behaviour is intact between commits.
6+
// See: https://github.com/nodejs/io.js/pull/2106
7+
8+
const common = require('../common');
9+
const assert = require('assert');
10+
const path = require('path');
11+
const pwd = process.cwd();
12+
13+
// join will internally ignore all the zero-length strings and it will return
14+
// '.' if the joined string is a zero-length string.
15+
assert.equal(path.join(''), '.');
16+
assert.equal(path.join('', ''), '.');
17+
assert.equal(path.join(pwd), pwd);
18+
assert.equal(path.join(pwd, ''), pwd);
19+
20+
// normalize will return '.' if the input is a zero-length string
21+
assert.equal(path.normalize(''), '.');
22+
assert.equal(path.normalize(pwd), pwd);
23+
24+
// Since '' is not a valid path in any of the common environments, return false
25+
assert.equal(path.isAbsolute(''), false);
26+
27+
// resolve, internally ignores all the zero-length strings and returns the
28+
// current working directory
29+
assert.equal(path.resolve(''), pwd);
30+
assert.equal(path.resolve('', ''), pwd);
31+
32+
// relative, internally calls resolve. So, '' is actually the current directory
33+
assert.equal(path.relative('', pwd), '');
34+
assert.equal(path.relative(pwd, ''), '');
35+
assert.equal(path.relative(pwd, pwd), '');

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.