-
Notifications
You must be signed in to change notification settings - Fork 171
-
Notifications
You must be signed in to change notification settings - Fork 171
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
links_in_email includes doctype uri and namespace #72
Comments
Here's a better solution: def links_in_email(email)
part = email.default_part
if part.content_type =~ /text\/html/
Nokogiri::HTML::Document.parse(part.body.to_s).search('a').map{|a| a[:href] }
else
URI.extract(part.body.to_s, ['http', 'https'])
end
end |
URI.extract("<a href=3D'http://example.org/'>Click me.</a>") # => ["http://example.org/'"] Using @nicholaides solution would require Nokogiri, so I would suggest using some simple regular expressions instead. |
Thanks for the workaround, @nicholaides! It would be nice if this could be fixed in this gem. Nokogiri seems like a much more reliable solution than regular expressions. If the dependency on Nokogiri is a problem (it's certainly not for me), what about making it optional? One could either |
Yeah, that sounds reasonable. I'll merge in a PR with optional Nokogiri support. |
this issue is pretty old, but still valid |
still valid and with a working fix, could you merge it ? |
In HTML emails
links_in_email
will include the URIs specified in the Doctype URI, any HTML namespace tags.e.g.
This breaks
click_first_link_in_email
for HTML emails because the first link is http://www.w3.org/TR/html4/loose.dtd in this example.I patched my version to this hacky solulution:
An ideal solution would probably use Nokogiri to get the links from all the
<a href=...>
elementsThe text was updated successfully, but these errors were encountered: