Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions stdlib/Markdown/src/Common/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,9 @@ end
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])?)*$"

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])
length(s) < 7 && return false
lowercase(first(s, 7)) == "mailto:" || return false
return occursin(_email_regex, s[nextind(s, 7):end])
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:[email protected]>" |> html == """<p><a href="mailto:[email protected]">mailto:[email protected]</a></p>\n"""
# not ok
@test md"<mailto [email protected]>" |> html == """<p>&lt;mailto [email protected]&gt;</p>\n"""
# see issue #42139
@test md"<一轮红日初升>" |> html == """<p>&lt;一轮红日初升&gt;</p>\n"""
end