Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report: handle invalid urls for source location items #11299

Merged
merged 4 commits into from Aug 24, 2020

Conversation

adrianaixba
Copy link
Collaborator

For #11261

Adds lh-link class to source-location render element. Needed to handle invalid URLs that didn’t create elements.

@adrianaixba adrianaixba requested a review from a team as a code owner August 21, 2020 17:05
@adrianaixba adrianaixba requested review from connorjclark and removed request for a team August 21, 2020 17:05
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@adrianaixba
Copy link
Collaborator Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@connorjclark
Copy link
Collaborator

connorjclark commented Aug 21, 2020

@adrianaixba you may wish to set your email for the Lighthouse repo (and all google git repos) to your google email: git config user.email <ldap>@google.com, which should avoid some troubles with CLA bot.

it('renders source-location with lh-link class for invalid urls', () => {
const sourceLocation = {
type: 'source-location',
url: 'invalid-url://www.example.com/script.js',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renderSourceLocation errors when _renderLink fails to create an anchor element, which only happens if item.url is an ill-formed URL or one of invalid protocol.

However, I'm having trouble understanding when that can happen, because if item.urlProvider === 'network', as is the case here, my understanding is that item.url must always be a valid URL of protocol http or https. This is set in just a handful of places [1], and I think each one is certain to come from a network record, thus must be a valid URL.

It's not trivial to see this, and clearly it's wrong as we've gotten an error report, so we should certainly guard against this in the details renderer. But I'd like to see an example of an erroring case so we can be sure that we are testing against the correct "bad url" here.

It'd help to find a reproduction case. I requested the issue filer to provide one #11261

[1]
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We found the error'ing url to be a relative url, like /url/main.js. Can you update the "invalid url" in this test to be that?

I'd also suggest a truly invalid url, one that would throw an error for new URL(), like new URL('atx')

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i helped with finding a renderer-side solution here, so i'm biased. but this lgtm. 👍

agree that there's extra work to harden the internals so this won't happen. #11261 (comment)

@connorjclark connorjclark changed the title report: handle invalid urls for source location elements report: handle invalid urls for source location items Aug 24, 2020
Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants