diff --git a/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row.js b/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row.js index 98acf6e38b..29019de589 100644 --- a/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row.js +++ b/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row.js @@ -66,7 +66,8 @@ _getLabelValue(labels, permittedLabels, label) { if (label.value) { return label.value; - } else if (labels[label.name].hasOwnProperty('default_value')) { + } else if (labels[label.name].hasOwnProperty('default_value') && + permittedLabels.hasOwnProperty(label.name)) { // default_value is an int, convert it to string label, e.g. "+1". return permittedLabels[label.name].find( value => parseInt(value, 10) === labels[label.name].default_value); diff --git a/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row_test.html b/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row_test.html index 0de437b3a6..537bd25544 100644 --- a/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row_test.html +++ b/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row_test.html @@ -281,5 +281,33 @@ limitations under the License. flushAsynchronousOperations(); assert.strictEqual(element.selectedValue, '-1'); }); + + test('default_value is null if not permitted', () => { + element.permittedLabels = { + Verified: [ + '-1', + ' 0', + '+1', + ], + }; + element.labels = { + 'Code-Review': { + values: { + '0': 'No score', + '+1': 'good', + '+2': 'excellent', + '-1': 'bad', + '-2': 'terrible', + }, + default_value: -1, + }, + }; + element.label = { + name: 'Code-Review', + value: null, + }; + flushAsynchronousOperations(); + assert.isNull(element.selectedValue); + }); });