diff --git a/fixtures/file - spaces.txt b/fixtures/file - spaces.txt new file mode 100644 index 0000000..84c22fd --- /dev/null +++ b/fixtures/file - spaces.txt @@ -0,0 +1 @@ +txt \ No newline at end of file diff --git a/lib/rsyncwrapper.js b/lib/rsyncwrapper.js index 626b198..a0f04fc 100644 --- a/lib/rsyncwrapper.js +++ b/lib/rsyncwrapper.js @@ -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 } diff --git a/lib/rsynwrapper.test.js b/lib/rsynwrapper.test.js index 2af98ab..d665e6c 100644 --- a/lib/rsynwrapper.test.js +++ b/lib/rsynwrapper.test.js @@ -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( @@ -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(