Skip to content

Commit

Permalink
Only tildify home at the beginning of a path (#6)
Browse files Browse the repository at this point in the history
Fixes #5.
  • Loading branch information
kevva authored and sindresorhus committed Apr 12, 2016
1 parent 0e4205e commit c57d405
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -5,5 +5,5 @@ var home = osHomedir();

module.exports = function (str) {
str = path.normalize(str) + path.sep;
return str.replace(home + path.sep, '~' + path.sep).slice(0, -1);
return (str.indexOf(home) === 0 ? str.replace(home + path.sep, '~' + path.sep) : str).slice(0, -1);
};
5 changes: 5 additions & 0 deletions test.js
Expand Up @@ -26,3 +26,8 @@ test('ignore relative paths', t => {
const fixture = 'tildify';
t.is(tildify(fixture), fixture);
});

test('only tildify when home is at the start of a path', t => {
const fixture = path.join('tildify', home);
t.is(tildify(fixture), fixture);
});

0 comments on commit c57d405

Please sign in to comment.