Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #16 from bengourley/master

Resolve relative paths
  • Loading branch information...
commit a6cfb35004783877196efe203b7a680e0ef26f39 2 parents 6dde83c + 8106437
@serby authored
Showing with 32 additions and 0 deletions.
  1. +8 −0 lib/map-path.js
  2. +24 −0 test/map-path.test.js
View
8 lib/map-path.js
@@ -25,11 +25,15 @@ module.exports = function(dirPath, params, callback) {
return callback(new Error('Path is required'))
}
+ // resolve '../'s
+ dirPath = path.resolve(dirPath)
+
// trim trailing slash
if (dirPath.substring(dirPath.length - 1) === '/') {
dirPath = dirPath.slice(0, -1);
}
+
function hash(filename, callback) {
var
md5sum = crypto.createHash('md5'),
@@ -47,6 +51,10 @@ module.exports = function(dirPath, params, callback) {
function makeHashMap (callback) {
var hashMap = Object.create(null)
async.forEach(files, function(filename, fileCallback) {
+
+ // resolve '../'s
+ filename = path.resolve(filename)
+
hash(filename, function(error, fileHash) {
var
View
24 test/map-path.test.js
@@ -106,6 +106,30 @@ describe('versionator', function() {
})
})
+ describe('relative paths', function () {
+
+ it('should resolve relative paths', function(done) {
+
+ versionator.createMapFromPath(tmpPath + '/a/..', function(error, results) {
+
+ var a = {
+ '/a': '/d41d8cd98f00b204e9800998ecf8427e/a',
+ '/b': '/8b1a9953c4611296a827abf8c47804d7/b',
+ '/c': '/e509465ef513154988e088d6ad3c21bf/c',
+ '/sub/a': '/sub/49f68a5c8493ec2c0bf489821c21fc3b/a'
+ }
+
+ a.should.eql(results)
+
+ done()
+
+ })
+
+ })
+
+
+ })
+
after(function(done) {
removeFiles(tmpPath, files, done)
})
Please sign in to comment.
Something went wrong with that request. Please try again.