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

Accidentally truncates file names ending with $$ #242

Closed
krainboltgreene opened this issue Apr 29, 2016 · 10 comments
Closed

Accidentally truncates file names ending with $$ #242

krainboltgreene opened this issue Apr 29, 2016 · 10 comments

Comments

@krainboltgreene
Copy link

So I thought it was a browserify-hmr issue but I looked into their tests and while I could produce an error I discovered via console log that fsExtra.copy was the point at which it incorrectly created a file. I'm now looking at fs-extra's tests to reproduce.

@jprichardson
Copy link
Owner

I'm now looking at fs-extra's tests to reproduce.

Thank you. This would be very helpful.

@krainboltgreene
Copy link
Author

I have written the test and it fails:

➜  node-fs-extra git:(master) ✗ node_modules/.bin/mocha lib/copy/__tests__/copy.test.js --grep 'should copy the file asynchronously'


  fs-extra
    + copy()
      > when the source is a file
        ✓ should copy the file asynchronously
        > with a weird name
          1) should copy the file asynchronously


  1 passing (84ms)
  1 failing

  1) fs-extra + copy() > when the source is a file > with a weird name should copy the file asynchronously:
     Uncaught Error: ENOENT: no such file or directory, open '/var/folders/z3/p9_b08g503jb3ndftzggrp5h0000gn/T/fs-extra/copy/TEST_fs-extra_copy$$'
      at Error (native)
      at Object.fs.openSync (fs.js:584:18)
      at Object.fs.readFileSync (fs.js:431:33)
      at lib/copy/__tests__/copy.test.js:59:58
      at doneOne (lib/copy/ncp.js:237:40)
      at lib/copy/ncp.js:122:11
      at FSReqWrap.oncomplete (fs.js:82:15)

@krainboltgreene
Copy link
Author

Here's a snapshot after disabling the afterHook:

ls /var/folders/z3/p9_b08g503jb3ndftzggrp5h0000gn/T/fs-extra/copy/
TEST_fs-extra_copy$ TEST_fs-extra_src$$

@krainboltgreene
Copy link
Author

The breaking code appears to be https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy/ncp.js#L82

console.log(targetPath)
/var/folders/z3/p9_b08g503jb3ndftzggrp5h0000gn/T/fs-extra/copy/TEST_fs-extra_copy$$
console.log(target)
/var/folders/z3/p9_b08g503jb3ndftzggrp5h0000gn/T/fs-extra/copy/TEST_fs-extra_copy$

@krainboltgreene
Copy link
Author

@jprichardson
Copy link
Owner

Ah, so it's treating it as Regex string that needs to be escaped.... hmm.

@krainboltgreene
Copy link
Author

Not quite? It's just because it thinks you might want special evaluation in the replacement string. It just turns out it always does this instead of only doing this on regexp first arguments.

@krainboltgreene
Copy link
Author

You know what I think I'm wrong on the why, but my guess is now after reading spec stuff is that they wanted string patterns to have some capture functionality.

@hhamilto
Copy link
Contributor

Unless any one else is feverishly working on this, I'd be delighted to submit a PR.

@krainboltgreene any chance you still have that test lying around? No worries if not, but I'd like to be sure that my changes fix your problem.

In any event, I'll write a test too.

@krainboltgreene
Copy link
Author

@hhamilto Any test you write that includes $$ in the string is sufficient, I think!

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

No branches or pull requests

4 participants