Closed
Description
This test shows that name
and ext
are not taken into account when using path.format
without a base
.
The common usage this is preventing is this:
var src = path.parse(srcpath)
src.base = null
if(src.ext === '') src.ext = '.js'
src = path.format(src)
However this doesn't do anything.
var path = require('path')
var assert = require('assert')
// pulled from https://nodejs.org/api/path.html#path_path_format_pathobject
/* global describe, it */
describe('node path', function () {
it('should work as documented', function () {
assert.equal(path.format({
root: '/',
dir: '/home/user/dir',
base: 'file.txt',
ext: '.txt',
name: 'file'
}), '/home/user/dir/file.txt')
})
it('should not work if missing base', function () {
assert.notEqual(path.format({
root: '/',
dir: '/home/user/dir',
ext: '.txt',
name: 'file'
}), '/home/user/dir/file.txt')
})
it('should show ext and name are irrelevant', function () {
assert.equal(path.format({
root: '/',
dir: '/home/user/dir',
ext: '.txt',
name: 'file'
}), path.format({
root: '/',
dir: '/home/user/dir'
}))
})
})
https://github.com/nodejs/io.js/blob/master/lib/path.js#L584
I can write a pull request, if anyone else thinks this is a good idea.