Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix resolving paths with certain special characters
  • Loading branch information
dougwilson committed Feb 13, 2018
1 parent 7330f71 commit fe5b805
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
@@ -1,6 +1,7 @@
unreleased
==========

* Fix resolving paths with certain special characters
* deps: http-errors@~1.6.2
- Make `message` property enumerable for `HttpError`s
- deps: depd@1.1.1
Expand Down
8 changes: 3 additions & 5 deletions index.js
Expand Up @@ -13,6 +13,7 @@
*/

var createError = require('http-errors')
var join = require('path').join
var normalize = require('path').normalize
var pathIsAbsolute = require('path-is-absolute')
var resolve = require('path').resolve
Expand Down Expand Up @@ -82,9 +83,6 @@ function resolvePath (rootPath, relativePath) {
throw createError(403)
}

// resolve & normalize the root path
root = normalize(resolve(root) + sep)

// resolve the path
return resolve(root, path)
// join the relative path
return normalize(join(resolve(root), path))
}
10 changes: 10 additions & 0 deletions test/resolvePath.js
Expand Up @@ -31,6 +31,11 @@ describe('resolvePath(relativePath)', function () {
normalize(join(process.cwd(), 'index.js')))
})

it('should resolve relative with special characters', function () {
assert.equal(normalize(resolvePath('f:oo$bar')),
normalize(join(process.cwd(), './f:oo$bar')))
})

it('should accept empty string', function () {
assert.equal(normalize(resolvePath('')),
normalize(process.cwd()))
Expand Down Expand Up @@ -89,6 +94,11 @@ describe('resolvePath(rootPath, relativePath)', function () {
normalize(resolve(__dirname, 'index.js')))
})

it('should resolve relative to rootPath with special characters', function () {
assert.equal(normalize(resolvePath(__dirname, 'f:oo$bar')),
normalize(resolve(__dirname, './f:oo$bar')))
})

it('should accept relative path', function () {
assert.equal(normalize(resolvePath(join(__dirname, '..'), 'index.js')),
normalize(resolve(join(__dirname, '..'), 'index.js')))
Expand Down

0 comments on commit fe5b805

Please sign in to comment.