From 323e871bbce475628883c6238b3cff2c4f9d6a47 Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Fri, 24 Aug 2018 09:23:12 -0700 Subject: [PATCH 1/3] URI encode relative path to filepatch This prevents us from borking the path for files that, for example, contain question marks. --- lib/controllers/file-patch-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/controllers/file-patch-controller.js b/lib/controllers/file-patch-controller.js index 90d6a67df8..49bf2f099c 100644 --- a/lib/controllers/file-patch-controller.js +++ b/lib/controllers/file-patch-controller.js @@ -37,7 +37,7 @@ export default class FilePatchController extends React.Component { static buildURI(relPath, workdir, stagingStatus) { return 'atom-github://file-patch/' + - relPath + + encodeURIComponent(relPath) + `?workdir=${encodeURIComponent(workdir)}` + `&stagingStatus=${encodeURIComponent(stagingStatus)}`; } From f368e601977d44917c2f522d59133e23ea3bed4b Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Fri, 24 Aug 2018 10:21:20 -0700 Subject: [PATCH 2/3] add unit test to ensure that components are uri encoded --- test/controllers/file-patch-controller.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/controllers/file-patch-controller.test.js b/test/controllers/file-patch-controller.test.js index a7b075e8ec..1529c3e284 100644 --- a/test/controllers/file-patch-controller.test.js +++ b/test/controllers/file-patch-controller.test.js @@ -96,6 +96,18 @@ describe('FilePatchController', function() { getFilePatchForPath = sinon.stub(repository, 'getFilePatchForPath'); }); + describe('buildURI', function() { + it('correctly uri encodes all components', function() { + const filePath = '???.txt'; + const stagingStatus = 'staged'; + const URI = FilePatchController.buildURI(filePath, workdirPath, stagingStatus); + assert.isTrue(URI.includes(encodeURIComponent(filePath))); + assert.isTrue(URI.includes(encodeURIComponent(workdirPath))); + assert.isTrue(URI.includes(encodeURIComponent(stagingStatus))); + }); + + }); + describe('when the FilePatch is too large', function() { it('renders a confirmation widget', async function() { From 755bacb76acfe2a210c8f99832e634c45f0a2583 Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Fri, 24 Aug 2018 10:47:58 -0700 Subject: [PATCH 3/3] :shirt: --- test/controllers/file-patch-controller.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/controllers/file-patch-controller.test.js b/test/controllers/file-patch-controller.test.js index 1529c3e284..2026f34079 100644 --- a/test/controllers/file-patch-controller.test.js +++ b/test/controllers/file-patch-controller.test.js @@ -98,10 +98,10 @@ describe('FilePatchController', function() { }); describe('buildURI', function() { it('correctly uri encodes all components', function() { - const filePath = '???.txt'; + const filePathWithSpecialChars = '???.txt'; const stagingStatus = 'staged'; - const URI = FilePatchController.buildURI(filePath, workdirPath, stagingStatus); - assert.isTrue(URI.includes(encodeURIComponent(filePath))); + const URI = FilePatchController.buildURI(filePathWithSpecialChars, workdirPath, stagingStatus); + assert.isTrue(URI.includes(encodeURIComponent(filePathWithSpecialChars))); assert.isTrue(URI.includes(encodeURIComponent(workdirPath))); assert.isTrue(URI.includes(encodeURIComponent(stagingStatus))); });