From 0ef65ee61845ce5ee93e632d96ae20558329f0ad Mon Sep 17 00:00:00 2001 From: Thibaut Lienart Date: Wed, 8 Sep 2021 12:16:36 +0200 Subject: [PATCH] (#42139) Fixes _is_mailto in resolution of autolink in Markdown module (#42140) --- stdlib/Markdown/src/Common/inline.jl | 7 ++----- stdlib/Markdown/test/runtests.jl | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/stdlib/Markdown/src/Common/inline.jl b/stdlib/Markdown/src/Common/inline.jl index d2855f27a7addd..fd5134481e113b 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 51f2e44c642cdb..dfe80430a00d6e 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