diff --git a/stdlib/Markdown/src/Common/inline.jl b/stdlib/Markdown/src/Common/inline.jl index d2855f27a7add..fd5134481e113 100644 --- a/stdlib/Markdown/src/Common/inline.jl +++ b/stdlib/Markdown/src/Common/inline.jl @@ -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 # ––––––––––– diff --git a/stdlib/Markdown/test/runtests.jl b/stdlib/Markdown/test/runtests.jl index 51f2e44c642cd..dfe80430a00d6 100644 --- a/stdlib/Markdown/test/runtests.jl +++ b/stdlib/Markdown/test/runtests.jl @@ -1251,3 +1251,12 @@ end """ @test_throws ErrorException Markdown.latex(s2) end + +@testset "issue #42139: autolink" begin + # ok + @test md"" |> html == """

mailto:foo@bar.com

\n""" + # not ok + @test md"" |> html == """

<mailto foo@bar.com>

\n""" + # see issue #42139 + @test md"<一轮红日初升>" |> html == """

<一轮红日初升>

\n""" +end