1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +00:00

fix: null tier name in inspector list (#5462)

This commit is contained in:
Charles Kerr 2023-04-26 23:27:17 -05:00 committed by GitHub
parent 15c3298211
commit 349a906f3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -724,6 +724,23 @@ export class Inspector extends EventTarget {
}; };
} }
static _getOrigin(tracker) {
try {
// `new URL` fails on FF and Chrome when the scheme is 'udp',
// so munge the URL to be something that won't break
const udp_prefix = 'udp://';
const is_udp = tracker.announce.startsWith(udp_prefix);
if (is_udp) {
const http_prefix = 'http://';
const munged = tracker.announce.replace(udp_prefix, http_prefix);
return new URL(munged).origin.replace(http_prefix, udp_prefix);
}
return new URL(tracker.announce).origin;
} catch {
return [tracker.sitename || tracker.host || tracker.announce];
}
}
_updateTiers() { _updateTiers() {
const na = 'N/A'; const na = 'N/A';
const { list } = this.elements.tiers; const { list } = this.elements.tiers;
@ -752,12 +769,7 @@ export class Inspector extends EventTarget {
tier_div.classList.add('tier-list-row', index % 2 ? 'odd' : 'even'); tier_div.classList.add('tier-list-row', index % 2 ? 'odd' : 'even');
let element = document.createElement('div'); let element = document.createElement('div');
let site = ''; const site = Inspector._getOrigin(tracker);
try {
site = new URL(tracker.announce).origin;
} catch {
site = [tracker.sitename || tracker.host || tracker.announce];
}
element.classList.add('tier-list-tracker'); element.classList.add('tier-list-tracker');
setTextContent(element, `${site} - tier ${tracker.tier + 1}`); setTextContent(element, `${site} - tier ${tracker.tier + 1}`);
element.setAttribute('title', tracker.announce); element.setAttribute('title', tracker.announce);