Skip to content

Backslash appears in autolinks when periods are escaped #388

Description

@ericli-splunk

When writing GitHub Flavored Markdown, I am escaping special characters using backslash (e.g. . -> \.). I found that when I enter a URL containing backslash escaped periods (\.), the rendered URL may also contain the backslash.
For example,

  • Input: http://github\.com
  • Actual output: <p><a href="http://github%5C.com">http://github\.com</a></p>
  • Expected output: <p><a href="http://github.com">http://github.com</a></p> or <p>http://github.com</p>

Also:

  • Input: www.github\.com
  • Actual output: <p><a href="http://www.github%5C.com">www.github\.com</a></p>
  • Expected output: <p><a href="http://www.github.com">www.github.com</a></p> or <p>www.github.com</p>

I think the GitHub Flavored Markdown Spec may be ambiguous in this case. In Section 6.1 (Backslash escapes) it says "Backslash escapes do not work in ... autolinks", such that http://example.com?find=\* can be rendered correctly. However in Section 6.9 (Autolinks (extension)) it says "An extended url autolink will be recognised when one of the schemes http://, or https://, followed by a valid domain". However, according to the spec valid domains cannot contain \.

Way to reproduce:

Enter the following to cmark-gfm -e autolink

1. http://github\.com
2. http\://github\.com
3. www.github.com
4. www.github\.com
5. www\.github\.com
6. www\.github.com

Result:

<ol>
<li><a href="http://github%5C.com">http://github\.com</a></li>
<li>http://github.com</li>
<li><a href="http://www.github.com">www.github.com</a></li>
<li><a href="http://www.github%5C.com">www.github\.com</a></li>
<li>www.github.com</li>
<li>www.github.com</li>
</ol>

My cmark-gfm --version:

cmark-gfm 0.29.0.gfm.13 - CommonMark with GitHub Flavored Markdown converter
(C) 2014-2016 John MacFarlane

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions