Bug 1563769 - Compile the regular expressions for computing the login title only once. r=MattN

Differential Revision: https://phabricator.services.mozilla.com/D37106

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jared Wein 2019-07-08 17:39:40 +00:00
Родитель 06ba061c26
Коммит 9367744c2b
1 изменённых файлов: 4 добавлений и 2 удалений

Просмотреть файл

@ -69,14 +69,16 @@ const convertSubjectToLogin = subject => {
return augmentVanillaLoginObject(login); return augmentVanillaLoginObject(login);
}; };
const SCHEME_REGEX = new RegExp(/^http(s)?:\/\//);
const SUBDOMAIN_REGEX = new RegExp(/^www\d*\./);
const augmentVanillaLoginObject = login => { const augmentVanillaLoginObject = login => {
let title; let title;
try { try {
title = new URL(login.origin).host; title = new URL(login.origin).host;
} catch (ex) { } catch (ex) {
title = login.origin; title = login.origin.replace(SCHEME_REGEX, "");
} }
title = title.replace(/^http(s)?:\/\//, "").replace(/^www\d*\./, ""); title = title.replace(SUBDOMAIN_REGEX, "");
return Object.assign({}, login, { return Object.assign({}, login, {
title, title,
}); });