Skip to content

Commit

Permalink
(#42139) Fixes _is_mailto in resolution of autolink in Markdown module (
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart authored Sep 8, 2021
1 parent 9e99af6 commit 47797a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 2 additions & 5 deletions stdlib/Markdown/src/Common/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,10 @@ function _is_link(s::AbstractString)
end

# non-normative regex from the HTML5 spec
const _email_regex = r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
const _email_regex = r"^mailto\:[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"

function _is_mailto(s::AbstractString)
length(s) < 6 && return false
# slicing strings is a bit risky, but this equality check is safe
lowercase(s[1:6]) == "mailto:" || return false
return occursin(_email_regex, s[6:end])
return occursin(_email_regex, s)
end

# –––––––––––
Expand Down
9 changes: 9 additions & 0 deletions stdlib/Markdown/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1251,3 +1251,12 @@ end
"""
@test_throws ErrorException Markdown.latex(s2)
end

@testset "issue #42139: autolink" begin
# ok
@test md"<mailto:foo@bar.com>" |> html == """<p><a href="mailto:foo@bar.com">mailto:foo@bar.com</a></p>\n"""
# not ok
@test md"<mailto foo@bar.com>" |> html == """<p>&lt;mailto foo@bar.com&gt;</p>\n"""
# see issue #42139
@test md"<一轮红日初升>" |> html == """<p>&lt;一轮红日初升&gt;</p>\n"""
end

0 comments on commit 47797a1

Please sign in to comment.