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

Escape '$' in replacement string for async file copying #291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/copy/__tests__/copy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ describe('fs-extra', function () {
})
})

it('should copy to a destination file with two \'$\' characters in name (eg: TEST_fs-extra_$$_copy)', function (done) {
var fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')
var fileDest = path.join(TEST_DIR, 'TEST_fs-extra_$$_copy')
fs.writeFileSync(fileSrc, '')

fse.copy(fileSrc, fileDest, function (err) {
assert(!err)
fs.statSync(fileDest)
done()
})
})

describe('> when the destination dir does not exist', function () {
it('should create the destination directory and copy the file', function (done) {
var src = path.join(TEST_DIR, 'file.txt')
Expand Down
2 changes: 1 addition & 1 deletion lib/copy/ncp.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function ncp (source, dest, options, callback) {
}

function onFile (file) {
var target = file.name.replace(currentPath, targetPath)
var target = file.name.replace(currentPath, targetPath.replace('$', '$$$$')) // escapes '$' with '$$'
isWritable(target, function (writable) {
if (writable) {
copyFile(file, target)
Expand Down