Preserve URL line numbers specified by @ Some URLs (for example, comment links in Gerrit emails) specify the line number following an @-sign rather than in the hash using an octothorp because the URL is already mostly inside a hash (for backward compatibility with the GWT UI). When these URLs do not include the project name (as they currently do not in Gerrit emails) the project is loaded and the parsed route is "upgraded" to include the project. However, when generating the upgrade URL, the `_generateUrl` method looks for the `lineNum` and `leftSide` properties to generate the address. While the address specified by the @-sign is properly converted to an octothorp-hash before this point, it appears on the properties object as `hash`, and is thus ignored by `_generateUrl`. With this change, instead of passing the raw hash through the app params and parsing it in the `gr-diff-view`, the hash is parsed into its `leftSide` and `lineNum` values and attached to the `app.params` by the router. In this way, the location is preserved through URL upgrade, the param format used in navigation matches that used in URL generation and the diff view no longer parses the route. Bug: Issue 7087 Change-Id: Idb2e3cccf2884fae742247cf1ebbde1ad97e53ab
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 250e0f5..e239bf0 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
@@ -509,7 +509,7 @@ getDiffComments() { return Promise.resolve({}); }, }); sandbox.stub(element.$.diff, 'reload'); - sandbox.stub(element, '_loadHash'); + sandbox.stub(element, '_initCursor'); element._loggedIn = true; element.params = { @@ -522,7 +522,7 @@ }; flush(() => { - assert.isTrue(element._loadHash.lastCall.calledWithExactly(10)); + assert.isTrue(element._initCursor.calledOnce); done(); }); }); @@ -573,31 +573,31 @@ assert.equal(select.nativeSelect.value, 'SIDE_BY_SIDE'); }); - test('_loadHash', () => { + test('_initCursor', () => { assert.isNotOk(element.$.cursor.initialLineNumber); - // Ignores invalid hashes: - element._loadHash('not valid'); + // Does nothing when params specify no cursor address: + element._initCursor({}); assert.isNotOk(element.$.cursor.initialLineNumber); - // Ignores null hash: - element._loadHash(null); + // Does nothing when params specify side but no number: + element._initCursor({leftSide: true}); assert.isNotOk(element.$.cursor.initialLineNumber); - // Revision hash: - element._loadHash('234'); + // Revision hash: specifies lineNum but not side. + element._initCursor({lineNum: 234}); assert.equal(element.$.cursor.initialLineNumber, 234); assert.equal(element.$.cursor.side, 'right'); - // Base hash: - element._loadHash('b345'); + // Base hash: specifies lineNum and side. + element._initCursor({leftSide: true, lineNum: 345}); assert.equal(element.$.cursor.initialLineNumber, 345); assert.equal(element.$.cursor.side, 'left'); - // GWT-style base hash: - element._loadHash('a123'); + // Specifies right side: + element._initCursor({leftSide: false, lineNum: 123}); assert.equal(element.$.cursor.initialLineNumber, 123); - assert.equal(element.$.cursor.side, 'left'); + assert.equal(element.$.cursor.side, 'right'); }); test('_shortenPath with long path should add ellipsis', () => {