From 20693de09f08de3b1b4933dd3e118945f3f100a4 Mon Sep 17 00:00:00 2001 From: Wyatt Allen Date: Tue, 1 Nov 2016 16:11:07 -0700 Subject: [PATCH] Properly encode file path in diff view Bug: Issue 4827 Change-Id: Ia0815aca6649324fe9f3ad7c5e2168c25d1f8a7d --- .../app/elements/diff/gr-diff-view/gr-diff-view.html | 1 + .../app/elements/diff/gr-diff-view/gr-diff-view.js | 3 ++- .../app/elements/diff/gr-diff-view/gr-diff-view_test.html | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html index 477034044a..cc172ace64 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html @@ -16,6 +16,7 @@ limitations under the License. + diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js index 7c5001d4ce..1cca11010c 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js @@ -92,6 +92,7 @@ behaviors: [ Gerrit.KeyboardShortcutBehavior, Gerrit.RESTClientBehavior, + Gerrit.URLEncodingBehavior, ], observers: [ @@ -389,7 +390,7 @@ _getDiffURL: function(changeNum, patchRange, path) { return '/c/' + changeNum + '/' + this._patchRangeStr(patchRange) + '/' + - path; + this.encodeURL(path, true); }, _computeDiffURL: function(changeNum, patchRangeRecord, path) { diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html index b0a0666731..99da821523 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html @@ -590,5 +590,13 @@ limitations under the License. assert.isTrue(replaceStateStub.called); }); + + test('_getDiffURL encodes special characters', function() { + var changeNum = 123; + var patchRange = {basePatchNum: 123, patchNum: 456}; + var path = 'c++/cpp.cpp'; + assert.equal(element._getDiffURL(changeNum, patchRange, path), + '/c/123/123..456/c%252B%252B/cpp.cpp'); + }); });