Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#42139) Fixes _is_mailto in resolution of autolink in Markdown module #42140

Merged
merged 3 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 5 deletions stdlib/Markdown/src/Common/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

# –––––––––––
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