Skip to content

Commit

Permalink
(#42139) Fixes _is_mailto in resolution of autolink in Markdown module (
Browse files Browse the repository at this point in the history
#42140)

(cherry picked from commit 47797a1)
  • Loading branch information
tlienart authored and KristofferC committed Nov 11, 2021
1 parent fa3d502 commit 7803c97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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
8 changes: 8 additions & 0 deletions stdlib/Markdown/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1230,3 +1230,11 @@ end
@test sprint(show, MIME("text/plain"), s) == " Misc:\n - line"
end

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

0 comments on commit 7803c97

Please sign in to comment.