Avoid JS error when a change has no id

This may cause the UI to display only a subset of the total changes,
leading to some confusion. Use the local variable that we define to be
set even when change.id is null consistently.

Change-Id: I7c5ff2d9c6ba83e8a8265df3fd83afabe1984fe2
This commit is contained in:
Jens Harbott 2017-10-04 13:12:04 +00:00
parent 850c940e1c
commit 898a8bf82a
1 changed files with 9 additions and 9 deletions

View File

@ -281,38 +281,38 @@
change_header: function(change) {
var change_id = change.id || 'NA';
if (change_id.length === 40) {
change_id = change_id.substr(0, 7);
}
var $change_link = $('<small />');
if (change.url !== null) {
var github_id = change.id.match(/^([0-9]+),([0-9a-f]{40})$/);
var github_id = change_id.match(/^([0-9]+),([0-9a-f]{40})$/);
if (github_id) {
$change_link.append(
$('<a />').attr('href', change.url).append(
$('<abbr />')
.attr('title', change.id)
.attr('title', change_id)
.text('#' + github_id[1])
)
);
} else if (/^[0-9a-f]{40}$/.test(change.id)) {
var change_id_short = change.id.slice(0, 7);
} else if (/^[0-9a-f]{40}$/.test(change_id)) {
var change_id_short = change_id.slice(0, 7);
$change_link.append(
$('<a />').attr('href', change.url).append(
$('<abbr />')
.attr('title', change.id)
.attr('title', change_id)
.text(change_id_short)
)
);
}
else {
$change_link.append(
$('<a />').attr('href', change.url).text(change.id)
$('<a />').attr('href', change.url).text(change_id)
);
}
}
else {
if (change_id.length === 40) {
change_id = change_id.substr(0, 7);
}
$change_link.text(change_id);
}