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

Temporary fix for UTF-8 bug in addressable #79

Merged
merged 2 commits into from Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/twingly/url.rb
Expand Up @@ -35,7 +35,9 @@ def internal_parse(potential_url)
scheme = addressable_uri.scheme
raise Twingly::URL::Error::ParseError unless scheme =~ ACCEPTED_SCHEMES

public_suffix_domain = PublicSuffix.parse(addressable_uri.display_uri.host)
display_uri = addressable_display_uri(addressable_uri)

public_suffix_domain = PublicSuffix.parse(display_uri.host)
raise Twingly::URL::Error::ParseError if public_suffix_domain.nil?

new(addressable_uri, public_suffix_domain)
Expand All @@ -56,7 +58,19 @@ def to_addressable_uri(potential_url)
end
end

private :new, :internal_parse, :to_addressable_uri
# Workaround for the following bug in addressable:
# https://github.com/sporkmonger/addressable/issues/224
def addressable_display_uri(addressable_uri)
addressable_uri.display_uri
rescue ArgumentError => error
if error.message.include?("invalid byte sequence in UTF-8")
raise Twingly::URL::Error::ParseError
end

raise
end

private :new, :internal_parse, :to_addressable_uri, :addressable_display_uri
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about splitting this line to multiple lines, so next time we get the nice diff :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. What is the best way of doing that?

private :new,
  :internal_parse,
  :to_addressable_uri,
  :addressable_display_uri

# or

private :new
private :internal_parse
private :to_addressable_uri
private :addressable_display_uri

For the second one we wouldn't have to add a , on the last line when adding a symbol, so I think that one looks best :).

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the second one (easier to remove/add line).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the second one too

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, sure let's go with the second one :)

Copy link
Member Author

Choose a reason for hiding this comment

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

end

def initialize(addressable_uri, public_suffix_domain)
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/twingly/url_spec.rb
Expand Up @@ -27,6 +27,8 @@ def invalid_urls
"http://xn--t...-/",
"http://xn--...-",
"leather beltsbelts for menleather beltmens beltsleather belts for menmens beltbelt bucklesblack l...",
"http://some_site.net%C2",
"http://+%D5d.some_site.net",
]
end

Expand Down