Double-encode file path for diff view
When navigating to diff view from change view, double-encode file path
to work around known pagejs library issue (see Issue 4255).
Bug: Issue 4474
Change-Id: I81bafcc86c4b2c450c92380eea52f315f5652b61
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
index c7034b5..8cc8506 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
@@ -378,12 +378,13 @@
},
_computeDiffURL: function(changeNum, patchRange, path) {
+ // @see Issue 4255 regarding double-encoding.
return '/c/' +
encodeURIComponent(changeNum) +
'/' +
encodeURIComponent(this._patchRangeStr(patchRange)) +
'/' +
- path;
+ encodeURIComponent(encodeURIComponent(path));
},
_patchRangeStr: function(patchRange) {
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
index f90ee68..1d62f33 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
@@ -296,5 +296,19 @@
assert.isFalse(element.diffs[0].hidden);
diffStub.restore();
});
+
+ test('file name should be double-escaped', function() {
+ element._files = [
+ {__path: 'my+file.txt'},
+ ];
+ element.changeNum = '42';
+ element.patchRange = {
+ basePatchNum: 'PARENT',
+ patchNum: '2',
+ };
+ flushAsynchronousOperations();
+ assert.equal(
+ element.$$('a').getAttribute('href'), '/c/42/2/my%252Bfile.txt');
+ });
});
</script>
diff --git a/polygerrit-ui/app/elements/core/gr-router/gr-router.js b/polygerrit-ui/app/elements/core/gr-router/gr-router.js
index ac9e03d..d9bf8ac 100644
--- a/polygerrit-ui/app/elements/core/gr-router/gr-router.js
+++ b/polygerrit-ui/app/elements/core/gr-router/gr-router.js
@@ -134,12 +134,13 @@
};
// Don't allow diffing the same patch number against itself.
if (params.basePatchNum === params.patchNum) {
+ // @see Issue 4255 regarding double-encoding.
page.redirect('/c/' +
encodeURIComponent(params.changeNum) +
'/' +
encodeURIComponent(params.patchNum) +
'/' +
- encodeURIComponent(params.path));
+ encodeURIComponent(encodeURIComponent(params.path)));
return;
}
normalizePatchRangeParams(params);