Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Irish <paulirish@users.noreply.github.com>
  • Loading branch information
alexnj and paulirish committed Dec 1, 2023
1 parent b2a0658 commit ab22847
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ class Util {
* @return {LH.Result.LhrEntity|string}
*/
static getEntityFromUrl(url, entities) {
// If it's a pre-v10 LHR, we don't have entities, so match against the root-ish domain
if (!entities) {
return Util.getLegacyRootDomain(url);
}

const entity = entities.find(e => e.origins.find(origin => url.startsWith(origin)));
// This fallback case would be unexpected, but leaving for safety.
return entity || Util.getLegacyRootDomain(url);
}

Expand Down Expand Up @@ -324,6 +326,8 @@ class Util {

/**
* Returns a primary domain for provided hostname (e.g. www.example.com -> example.com).
* As it doesn't consult the Public Suffix List, it can sometimes lose detail.
* See the `listOfTlds` comment above for more.
* This function is used only while rendering pre-10.0 LHRs.
* @param {string|URL} url hostname or URL object
* @return {string}
Expand Down

0 comments on commit ab22847

Please sign in to comment.