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

fix: avoid panics in ParseNode() #21

Merged
merged 2 commits into from
Jan 31, 2023
Merged

fix: avoid panics in ParseNode() #21

merged 2 commits into from
Jan 31, 2023

Conversation

nekr0z
Copy link
Contributor

@nekr0z nekr0z commented Jan 30, 2023

this fixes #20

ParseNode(node, nil) should be able to avoid panic even if node does not contain a valid absolute base path in its <head>, since there can be usable microformats with absolute paths or no paths.

ParseNode(nil, base) should return nil instead of panic, because why panic?

ParseNode(node, nil) should be able to avoid panic even if node does
not contain a valid absolute base path in its <head>, since there can
be usable microformats with absolute paths or no paths.

ParseNode(nil, base) should return nil instead of panic, because why
panic?
Copy link
Owner

@willnorris willnorris left a comment

Choose a reason for hiding this comment

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

because why panic?

Why indeed? :) This looks good to me, just a couple of minor comments below. Thanks!

microformats_test.go Outdated Show resolved Hide resolved
microformats_test.go Outdated Show resolved Hide resolved
microformats.go Outdated
@@ -118,13 +118,19 @@ func Parse(r io.Reader, baseURL *url.URL) *Data {
// ParseNode parses the microformats found in doc. baseURL is the URL this
// document was retrieved from and is used to resolve any relative URLs.
Copy link
Owner

Choose a reason for hiding this comment

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

I think it's worth updating the godoc to clarify the behavior when baseURL is nil. Something like If baseURL is nil, relative URLs are not expanded. If you don't mind, maybe also change "resolve" to "expanded" in that last sentence as well, since we're not actually doing any URL resolution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, as long as an absolute base URL is in the document (i.e. <base href="https://example.com"> we do expand the relative URLs even if baseURL is nil.

I tried to document this (also in Parse() for consistency), but the wording remains clumsy IMO.

@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2023

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (8b8e597) compared to base (ffbbdae).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #21   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          837       843    +6     
=========================================
+ Hits           837       843    +6     
Impacted Files Coverage Δ
microformats.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@willnorris
Copy link
Owner

awesome, thanks!

@willnorris willnorris merged commit 3f6d1e0 into willnorris:main Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when calling ParseNode with nil arguments
3 participants