Fix invalid anchored links due to "//" prefix. (#4340)

This commit is contained in:
Michel 2019-10-09 19:57:58 +02:00 committed by Ben Halpern
parent e579b03af1
commit 7d530cf002
2 changed files with 8 additions and 0 deletions

View file

@ -16,6 +16,8 @@ module Redcarpet
end
if (/\A(https?:\/\/)/.match? link) || link.nil?
%(<a href="#{link}"#{link_attributes}>#{content}</a>)
elsif link.start_with?("#")
%(<a href="#{link}"#{link_attributes}>#{content}</a>)
else
%(<a href="//#{link}"#{link_attributes}>#{content}</a>)
end

View file

@ -77,6 +77,12 @@ RSpec.describe MarkdownParser do
test = generate_and_parse_markdown(code_span)
expect(test).to eq("<p><a href=\"//github.com\">github</a></p>\n\n")
end
it "renders properly anchored links" do
code_span = "[Chapter 1](#chapter-1)"
test = generate_and_parse_markdown(code_span)
expect(test).to eq("<p><a href=\"#chapter-1\">Chapter 1</a></p>\n\n")
end
end
describe "mentions" do