Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make str.replace strict? #3

Closed
fritx opened this issue Sep 11, 2015 · 4 comments
Closed

Make str.replace strict? #3

fritx opened this issue Sep 11, 2015 · 4 comments

Comments

@fritx
Copy link
Contributor

fritx commented Sep 11, 2015

Hey @sindresorhus
How about this? also would work in untildify

module.exports = function (str) {
    return str.replace(home, '~');
};

=>

module.exports = function (str) {
  str += path.sep;
  str = str.replace(home + path.sep, '~' + path.sep);
  str = str.slice(0, -1);
  return str;
};
test(function (t) {
  var fixture = home;
  t.assert(tildify(fixture) === '~');
  t.end();
});

test(function (t) {
  var fixture = path.resolve(home, 'tildify');
  t.assert(tildify(fixture)[0] === '~');
  t.assert(/tildify$/.test(tildify(fixture)));
  t.assert(tildify(fixture) !== fixture);
  t.end();
});

test(function (t) {
  var fixture = path.resolve(home + 'foo', 'tildify');
  t.assert(tildify(fixture) === fixture);
  t.end();
});

image

@sindresorhus
Copy link
Owner

I'm not exactly sure what you're asking here? Can you succinctly explain it?

@fritx
Copy link
Contributor Author

fritx commented Sep 11, 2015

Ok. We should make sure that tildify applied to path.resolve(home, 'tildify') and not to path.resolve(home + 'foo', 'tildify') (which might not be the current homedir)

(home == '/Users/fritx')
/Users/fritx/abc =(√)> ~/abc
/Users/fritxfoo/abc =(×)> ~foo/abc   (is that right?)

@sindresorhus
Copy link
Owner

Oh yeah. I doubt that will ever happen, but I agree, doesn't hurt to be strict. Wanna do a PR?

@fritx
Copy link
Contributor Author

fritx commented Sep 11, 2015

Thanks. I'm ready for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants