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 spaces with dash #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions fixtures/file - spaces.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
txt
2 changes: 1 addition & 1 deletion lib/rsyncwrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var util = require('util')

var escapeSpaces = function(path) {
if (typeof path === 'string') {
return path.replace(/\b\s/g, '\\ ')
return path.replace(/(\s+)/g, '\\$1')
} else {
return path
}
Expand Down
31 changes: 31 additions & 0 deletions lib/rsynwrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ test('syncs a single file with spaces in filename', done => {
)
})

test('syncs a single file with spaces and dash in filename', done => {
const rsync = require('../lib/rsyncwrapper')
rsync({
src: 'fixtures/file - spaces.txt',
dest: 'tmp/',
},
err => {
expect(err).toBeNull()
expect(existsSync('tmp/file - spaces.txt')).toBe(true)
done()
}
)
})

test('syncs a single file with spaces in filename and dest folder', done => {
const rsync = require('../lib/rsyncwrapper')
rsync(
Expand Down Expand Up @@ -104,6 +118,23 @@ test('handles pre-escaped paths', done => {
)
})

test('handles pre-escaped paths with dash and spaces', done => {
const rsync = require('../lib/rsyncwrapper')
rsync({
// prettier-ignore
src: 'fixtures/file\ -\ spaces.txt',
// prettier-ignore
dest: 'tmp\ with\ spaces/'
},
err => {
expect(err).toBeNull()
// prettier-ignore
expect(existsSync('tmp\ with\ spaces/file\ -\ spaces.txt')).toBe(true)
done()
}
)
})

test('syncs multiple files', done => {
const rsync = require('../lib/rsyncwrapper')
rsync(
Expand Down