From 3c0b11dfc5a3a226903719815be46e3d3996b698 Mon Sep 17 00:00:00 2001 From: MarshallRJ Date: Wed, 3 Jul 2019 07:16:31 +0200 Subject: [PATCH 1/3] [test] add test file with dash in the filename --- fixtures/file - spaces.txt | 1 + lib/rsynwrapper.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 fixtures/file - spaces.txt 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/rsynwrapper.test.js b/lib/rsynwrapper.test.js index 2af98ab..96bb5a8 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( From 6a77f749b4c8359931f5cf945f64cfc7cb76b910 Mon Sep 17 00:00:00 2001 From: MarshallRJ Date: Wed, 3 Jul 2019 07:19:11 +0200 Subject: [PATCH 2/3] [fix] regex to escape spaces --- lib/rsyncwrapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From ad9342667fca080a6ac4bc9bf7bc6053e7289097 Mon Sep 17 00:00:00 2001 From: MarshallRJ Date: Wed, 3 Jul 2019 07:24:52 +0200 Subject: [PATCH 3/3] [test] add test for escaped file with spaces --- lib/rsynwrapper.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/rsynwrapper.test.js b/lib/rsynwrapper.test.js index 96bb5a8..d665e6c 100644 --- a/lib/rsynwrapper.test.js +++ b/lib/rsynwrapper.test.js @@ -118,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(