Skip to content

Commit 47797a1

Browse files
authored
(#42139) Fixes _is_mailto in resolution of autolink in Markdown module (#42140)
1 parent 9e99af6 commit 47797a1

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,3 +1251,12 @@ end
12511251
"""
12521252
@test_throws ErrorException Markdown.latex(s2)
12531253
end
1254+
1255+
@testset "issue #42139: autolink" begin
1256+
# ok
1257+
@test md"<mailto:[email protected]>" |> html == """<p><a href="mailto:[email protected]">mailto:[email protected]</a></p>\n"""
1258+
# not ok
1259+
@test md"<mailto [email protected]>" |> html == """<p>&lt;mailto [email protected]&gt;</p>\n"""
1260+
# see issue #42139
1261+
@test md"<一轮红日初升>" |> html == """<p>&lt;一轮红日初升&gt;</p>\n"""
1262+
end

0 commit comments

Comments
 (0)