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

Relaxing Email/URL validation for autolinking? #293

Closed
eideer opened this Issue Oct 21, 2015 · 5 comments

Comments

Projects
None yet
3 participants
@eideer

eideer commented Oct 21, 2015

Would it be possible to relax the validation of email addresses for autolinking?

Even just simple non-alphanum characters like underscore seem to be disallowed in Ruby 2.x

  • with underscore, no autolinking
require 'kramdown'
=> true 

text = %{
$C
Email: <t_leitner@gmx.at>
$C
}
=> "\n$C\nEmail: <t_leitner@gmx.at>\n$C\n" 

Kramdown::Document.new(text).to_html
=> "\n<p>$C\nEmail: &lt;t_leitner@gmx.at&gt;\n$C</p>\n" 
  • without underscore, autolinking
require 'kramdown'
=> true 

text = %{
$C
Email: <t.leitner@gmx.at>
$C
}
 => "\n$C\nEmail: <t.leitner@gmx.at>\n$C\n" 

Kramdown::Document.new(text).to_html
=> "\n<p>$C\nEmail: <a href=\"&#109;&#097;&#105;&#108;&#116;&#111;:&#116;&#046;&#108;&#101;&#105;&#116;&#110;&#101;&#114;&#064;&#103;&#109;&#120;&#046;&#097;&#116;\">&#116;&#046;&#108;&#101;&#105;&#116;&#110;&#101;&#114;&#064;&#103;&#109;&#120;&#046;&#097;&#116;</a>\n$C</p>\n" 

@gettalong gettalong self-assigned this Oct 21, 2015

@gettalong

This comment has been minimized.

Owner

gettalong commented Oct 21, 2015

In those cases you can prepend the protocol (ie. <mailto:t_leitner@gmx.at>) and it will work.

However, the underscore is definitely missing from the allowed characters for Ruby versions >= 1.9.0 in the protocol-less form - thanks for reporting!

Adding anything other than underscore would potentially break backwards-compatibility.

@gettalong gettalong added the bug label Oct 21, 2015

@gettalong gettalong closed this in 1be77ee Feb 18, 2016

@eideer

This comment has been minimized.

eideer commented Feb 18, 2016

Thank you! Have been using <mailto: .. > prefix and that works, but nice to have the option without thanks for adding the underscore @gettalong

@benhyland

This comment has been minimized.

benhyland commented Apr 21, 2016

Similarly, we ran into an issue with apostrophes in email links:

=> "Email without apostrophe <foo@example.com>"
irb(main):019:0> Kramdown::Document.new(text).to_html
=> "<p>Email without apostrophe <a href=\"&#109;&#097;&#105;&#108;&#116;&#111;:&#102;&#111;&#111;&#064;&#101;&#120;&#097;&#109;&#112;&#108;&#101;&#046;&#099;&#111;&#109;\">&#102;&#111;&#111;&#064;&#101;&#120;&#097;&#109;&#112;&#108;&#101;&#046;&#099;&#111;&#109;</a></p>\n"
irb(main):020:0> text = "Email with apostrophe <fo'o@example.com>"
=> "Email with apostrophe <fo'o@example.com>"
irb(main):021:0> Kramdown::Document.new(text).to_html
=> "<p>Email with apostrophe &lt;fo’o@example.com&gt;</p>\n"
irb(main):022:0> text = "Email with apostrophe <mailto:fo'o@example.com>"
=> "Email with apostrophe <mailto:fo'o@example.com>"
irb(main):023:0> Kramdown::Document.new(text).to_html
=> "<p>Email with apostrophe <a href=\"&#109;&#097;&#105;&#108;&#116;&#111;:&#102;&#111;&#039;&#111;&#064;&#101;&#120;&#097;&#109;&#112;&#108;&#101;&#046;&#099;&#111;&#109;\">&#102;&#111;&#039;&#111;&#064;&#101;&#120;&#097;&#109;&#112;&#108;&#101;&#046;&#099;&#111;&#109;</a></p>\n"

Using mailto in the link works.
Apostrophe is valid in email addresses in the local part.
I didn't understand the reason to decide not to fix this in the previous example - can you explain any further?
Many thanks.

@eideer

This comment has been minimized.

eideer commented Apr 21, 2016

There seems to be some Ruby version dependency in the mailto autolinking, Ideally, the format of the mailto link would be agnostic of this, but maybe it's hard to write a regex that works across Ruby versions, eg.

if RUBY_VERSION == '1.8.5'
ACHARS = '\w\x80-\xFF'
elsif RUBY_VERSION < '1.9.0'
ACHARS = '\w'
else
ACHARS = '[[:alnum:]]_'
end
AUTOLINK_START_STR = "<((mailto|https?|ftps?):.+?|[-.#{ACHARS}]+@[-#{ACHARS}]+(?:\.[-#{ACHARS}]+)*\.[a-z]+)>"

@gettalong

This comment has been minimized.

Owner

gettalong commented May 1, 2016

@benhyland @erikse The shorthand version only works for the most common case, for everything else the full version including 'mailto:' has to be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment