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)}`; } diff --git a/test/controllers/file-patch-controller.test.js b/test/controllers/file-patch-controller.test.js index a7b075e8ec..2026f34079 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 filePathWithSpecialChars = '???.txt'; + const stagingStatus = 'staged'; + 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))); + }); + + }); + describe('when the FilePatch is too large', function() { it('renders a confirmation widget', async function() {