Skip to content

Commit 41e53e5

Browse files
Paul Serbypiscisaureus
authored andcommitted
path: add platform specific path delimiter
Closes nodejs#3728 Closes nodejs#4071
1 parent 3053f4d commit 41e53e5

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

doc/api/path.markdown

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Normalize a string path, taking care of `'..'` and `'.'` parts.
1414

1515
When multiple slashes are found, they're replaced by a single one;
1616
when the path contains a trailing slash, it is preserved.
17-
On windows backslashes are used.
17+
On Windows backslashes are used.
1818

1919
Example:
2020

@@ -44,7 +44,7 @@ Resolves `to` to an absolute path.
4444
If `to` isn't already absolute `from` arguments are prepended in right to left
4545
order, until an absolute path is found. If after using all `from` paths still
4646
no absolute path is found, the current working directory is used as well. The
47-
resulting path is normalized, and trailing slashes are removed unless the path
47+
resulting path is normalized, and trailing slashes are removed unless the path
4848
gets resolved to the root directory. Non-string arguments are ignored.
4949

5050
Another way to think of it is as a sequence of `cd` commands in a shell.
@@ -143,14 +143,36 @@ an empty string. Examples:
143143

144144
The platform-specific file separator. `'\\'` or `'/'`.
145145

146-
An example on linux:
146+
An example on *nix:
147147

148148
'foo/bar/baz'.split(path.sep)
149149
// returns
150150
['foo', 'bar', 'baz']
151151

152-
An example on windows:
152+
An example on Windows:
153153

154154
'foo\\bar\\baz'.split(path.sep)
155155
// returns
156156
['foo', 'bar', 'baz']
157+
158+
## path.delimiter
159+
160+
The platform-specific path delimiter, `;` or `':'`.
161+
162+
An example on *nix:
163+
164+
console.log(process.env.PATH)
165+
// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
166+
167+
process.env.PATH.split(path.delimiter)
168+
// returns
169+
['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
170+
171+
An example on Windows:
172+
173+
console.log(process.env.PATH)
174+
// 'C:\Windows\system32;C:\Windows;C:\Program Files\nodejs\'
175+
176+
process.env.PATH.split(path.delimiter)
177+
// returns
178+
['C:\Windows\system32', 'C:\Windows', 'C:\Program Files\nodejs\']

lib/path.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ if (isWindows) {
262262
};
263263

264264
exports.sep = '\\';
265+
exports.delimiter = ';';
265266

266267
} else /* posix */ {
267268

@@ -378,6 +379,7 @@ if (isWindows) {
378379
};
379380

380381
exports.sep = '/';
382+
exports.delimiter = ':';
381383
}
382384

383385

test/simple/test-path.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,18 @@ assert.equal(failures.length, 0, failures.join(''));
277277

278278
// path.sep tests
279279
if (isWindows) {
280-
// windows
281-
assert.equal(path.sep, '\\');
280+
// windows
281+
assert.equal(path.sep, '\\');
282+
} else {
283+
// posix
284+
assert.equal(path.sep, '/');
285+
}
286+
287+
// path.delimiter tests
288+
if (isWindows) {
289+
// windows
290+
assert.equal(path.delimiter, ';');
282291
} else {
283-
// posix
284-
assert.equal(path.sep, '/');
292+
// posix
293+
assert.equal(path.delimiter, ':');
285294
}

0 commit comments

Comments
 (0)