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

Relaxing Email/URL validation for autolinking? #293

Closed
erkde opened this issue Oct 21, 2015 · 5 comments
Closed

Relaxing Email/URL validation for autolinking? #293

erkde opened this issue Oct 21, 2015 · 5 comments
Assignees
Labels

Comments

@erkde
Copy link

erkde 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
Copy link
Owner

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.

@erkde
Copy link
Author

erkde 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
Copy link

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.

@erkde
Copy link
Author

erkde 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
Copy link
Owner

@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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants