Skip to content

Commit

Permalink
Temporary fix for UTF-8 bug in addressable
Browse files Browse the repository at this point in the history
Temporary fix for #62.

Related to sporkmonger/addressable#224
  • Loading branch information
roback committed Feb 1, 2016
1 parent 1bb1896 commit cc65635
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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
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

0 comments on commit cc65635

Please sign in to comment.