Navigation Menu

Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
- Use indexOf instead of startsWith.
Browse files Browse the repository at this point in the history
- Use 4 space indents.
- Add unit test.
  • Loading branch information
ckearney committed Sep 12, 2016
1 parent 9711813 commit 88b295b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 9 additions & 7 deletions index.js
Expand Up @@ -27,13 +27,15 @@ var getConfig = function() {
};

function normalizePath(full) {
var dir_name = path.resolve(full);

if(dir_name.startsWith('\\\\?\\')){
dir_name = dir_name.substring(4, dir_name.length);
}
dir_name += (dir_name[dir_name.length - 1] === path.sep) ? '' : path.sep;
return dir_name;
var dir_name = full;

if(dir_name.indexOf('\\\\?\\') === 0){
dir_name = dir_name.substring(4, dir_name.length);
}
dir_name = path.resolve(dir_name);

dir_name += (dir_name[dir_name.length - 1] === path.sep) ? '' : path.sep;
return dir_name;
}


Expand Down
10 changes: 10 additions & 0 deletions tests/index.js
Expand Up @@ -307,4 +307,14 @@ describe('fslock unit tests', function() {
assert.ok(true);
});

it('should work with windows style paths', function() {
fsLock({
'open_basedir': ['/'],
'file_accessdir': ['/']
});
// Simulate the path._makeLong prefix on windows.
var dir_name = fsLock.normalizePath('\\\\?\\/tmp');
assert.equal('/tmp/', dir_name);
});

});

0 comments on commit 88b295b

Please sign in to comment.