Skip to content

Commit a8722c6

Browse files
tlienartKristofferC
authored andcommitted
(#42139) Fixes _is_mailto in resolution of autolink in Markdown module (#42140)
(cherry picked from commit 47797a1)
1 parent c6a090f commit a8722c6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

stdlib/Markdown/src/Common/inline.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,10 @@ function _is_link(s::AbstractString)
146146
end
147147

148148
# non-normative regex from the HTML5 spec
149-
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])?)*$"
149+
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])?)*$"
150150

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

158155
# –––––––––––

stdlib/Markdown/test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,11 @@ end
12301230
@test sprint(show, MIME("text/plain"), s) == " Misc:\n - line"
12311231
end
12321232

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

0 commit comments

Comments
 (0)