Skip to content

~foobar maps to /home/foobar/foobar #12

@amagura

Description

@amagura

file.path.abspath('~foobar') incorrectly maps ~foobar to $HOME/foobar instead of the expected /home/foobar.

One suggestion would be to check to see if an unescaped ~ is present in provided path and then check if there are no filesystem path delimiters:

function abspath(path) {
   if (path.match(/\//) === null && path.match(/\\~/) === null) {
     /* path probably refers to a user's home directory */
   } else {
    /* path probably doesn't refer to a user's home directory */
   }
});

Or you could try something like this, assuming you can find a reliable means of getting user x's $HOME:

a = '~<USER>';
b = '\\~<USER>';

a.replace(/~.*/, <USERS HOME>) === <USERS HOME>
// true

b.replace(/~.*/, <USERS HOME>) === <USERS HOME>
// false

/* only works if USER is `foobar` */
a = '~foobar';
b = '\\~foobar';

a.replace(/~.*/, process.env.HOME) === process.env.HOME
// true

b.replace(/~.*/, process.env.HOME) === process.env.HOME
// false

or something like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions