doc,test: empty strings in path module
The path module's `join, normalize, isAbsolute, relative and resolve`
functions return/use the current directory if they are passed zero
length strings.
> process.version
'v2.3.4-pre'
> path.win32.join('')
'.'
> path.posix.join('')
'.'
> path.win32.normalize('')
'.'
> path.posix.normalize('')
'.'
> path.win32.isAbsolute('')
false
> path.posix.isAbsolute('')
false
> path.win32.relative('', '')
''
> path.posix.relative('', '')
''
> path.win32relative('.', '')
''
> path.posix.relative('.', '')
''
> path.posix.resolve('')
'/home/thefourtheye/Desktop'
> path.win32.resolve('')
'\\home\\thefourtheye\\Desktop'
Since empty paths are not valid in any of the operating systems people
normally use, this behaviour might be a surprise to the users. This
commit introduces "Notes" about this, wherever applicable in `path`'s
documentation.
The tests makes sure that the behaviour is intact between
commits.
PR-URL: https://github.com/nodejs/io.js/pull/2106
Reviewed-By: Rich Trott <rtrott@gmail.com>
10 years ago
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// These testcases are specific to one uncommon behaviour in path module. Few
|
|
|
|
// of the functions in path module, treat '' strings as current working
|
|
|
|
// directory. This test makes sure that the behaviour is intact between commits.
|
|
|
|
// See: https://github.com/nodejs/node/pull/2106
|
doc,test: empty strings in path module
The path module's `join, normalize, isAbsolute, relative and resolve`
functions return/use the current directory if they are passed zero
length strings.
> process.version
'v2.3.4-pre'
> path.win32.join('')
'.'
> path.posix.join('')
'.'
> path.win32.normalize('')
'.'
> path.posix.normalize('')
'.'
> path.win32.isAbsolute('')
false
> path.posix.isAbsolute('')
false
> path.win32.relative('', '')
''
> path.posix.relative('', '')
''
> path.win32relative('.', '')
''
> path.posix.relative('.', '')
''
> path.posix.resolve('')
'/home/thefourtheye/Desktop'
> path.win32.resolve('')
'\\home\\thefourtheye\\Desktop'
Since empty paths are not valid in any of the operating systems people
normally use, this behaviour might be a surprise to the users. This
commit introduces "Notes" about this, wherever applicable in `path`'s
documentation.
The tests makes sure that the behaviour is intact between
commits.
PR-URL: https://github.com/nodejs/io.js/pull/2106
Reviewed-By: Rich Trott <rtrott@gmail.com>
10 years ago
|
|
|
|
|
|
|
require('../common');
|
doc,test: empty strings in path module
The path module's `join, normalize, isAbsolute, relative and resolve`
functions return/use the current directory if they are passed zero
length strings.
> process.version
'v2.3.4-pre'
> path.win32.join('')
'.'
> path.posix.join('')
'.'
> path.win32.normalize('')
'.'
> path.posix.normalize('')
'.'
> path.win32.isAbsolute('')
false
> path.posix.isAbsolute('')
false
> path.win32.relative('', '')
''
> path.posix.relative('', '')
''
> path.win32relative('.', '')
''
> path.posix.relative('.', '')
''
> path.posix.resolve('')
'/home/thefourtheye/Desktop'
> path.win32.resolve('')
'\\home\\thefourtheye\\Desktop'
Since empty paths are not valid in any of the operating systems people
normally use, this behaviour might be a surprise to the users. This
commit introduces "Notes" about this, wherever applicable in `path`'s
documentation.
The tests makes sure that the behaviour is intact between
commits.
PR-URL: https://github.com/nodejs/io.js/pull/2106
Reviewed-By: Rich Trott <rtrott@gmail.com>
10 years ago
|
|
|
const assert = require('assert');
|
|
|
|
const path = require('path');
|
|
|
|
const pwd = process.cwd();
|
|
|
|
|
|
|
|
// join will internally ignore all the zero-length strings and it will return
|
|
|
|
// '.' if the joined string is a zero-length string.
|
|
|
|
assert.equal(path.join(''), '.');
|
|
|
|
assert.equal(path.join('', ''), '.');
|
|
|
|
assert.equal(path.join(pwd), pwd);
|
|
|
|
assert.equal(path.join(pwd, ''), pwd);
|
|
|
|
|
|
|
|
// normalize will return '.' if the input is a zero-length string
|
|
|
|
assert.equal(path.normalize(''), '.');
|
|
|
|
assert.equal(path.normalize(pwd), pwd);
|
|
|
|
|
|
|
|
// Since '' is not a valid path in any of the common environments, return false
|
|
|
|
assert.equal(path.isAbsolute(''), false);
|
|
|
|
|
|
|
|
// resolve, internally ignores all the zero-length strings and returns the
|
|
|
|
// current working directory
|
|
|
|
assert.equal(path.resolve(''), pwd);
|
|
|
|
assert.equal(path.resolve('', ''), pwd);
|
|
|
|
|
|
|
|
// relative, internally calls resolve. So, '' is actually the current directory
|
|
|
|
assert.equal(path.relative('', pwd), '');
|
|
|
|
assert.equal(path.relative(pwd, ''), '');
|
|
|
|
assert.equal(path.relative(pwd, pwd), '');
|