diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js index edb676effd..ba5138fc5a 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js +++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js @@ -908,7 +908,8 @@ !chunk.ab && // The chunk doesn't have the given side. - ((leftSide && !chunk.a) || (!leftSide && !chunk.b))); + ((leftSide && (!chunk.a || !chunk.a.length)) || + (!leftSide && (!chunk.b || !chunk.b.length)))); // If we reached the beginning of the diff and failed to find a chunk // with the given side, return null. diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff_test.html b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff_test.html index 5366664f6a..082a03220f 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff_test.html +++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff_test.html @@ -851,7 +851,7 @@ limitations under the License. assert.equal(element._lastChunkForSide(diff, true), diff.content[3]); }); - test('addition', () => { + test('addition with a undefined', () => { const diff = {content: [ {b: ['foo', 'bar', 'baz']}, ]}; @@ -859,7 +859,16 @@ limitations under the License. assert.isNull(element._lastChunkForSide(diff, true)); }); - test('deletion', () => { + test('addition with a empty', () => { + const diff = {content: [ + {a: [], b: ['foo', 'bar', 'baz']}, + ]}; + assert.equal(element._lastChunkForSide(diff, false), diff.content[0]); + assert.isNull(element._lastChunkForSide(diff, true)); + }); + + + test('deletion with b undefined', () => { const diff = {content: [ {a: ['foo', 'bar', 'baz']}, ]}; @@ -867,6 +876,14 @@ limitations under the License. assert.equal(element._lastChunkForSide(diff, true), diff.content[0]); }); + test('deletion with b empty', () => { + const diff = {content: [ + {a: ['foo', 'bar', 'baz'], b: []}, + ]}; + assert.isNull(element._lastChunkForSide(diff, false)); + assert.equal(element._lastChunkForSide(diff, true), diff.content[0]); + }); + test('empty', () => { const diff = {content: []}; assert.isNull(element._lastChunkForSide(diff, false));