From af6be75adb99ff42215a945927c016aa5e40dab2 Mon Sep 17 00:00:00 2001
From: Dejan Kitic <137049545+dek5troza@users.noreply.github.com>
Date: Sun, 20 Apr 2025 12:18:14 +0100
Subject: Valid email address should only start with alphanumeric (#28174)
This fixes issue #27847 where regular expression allowed email address
to start with special symbols. Valid email addresses should start with
alphanumeric character, and as such will be rendered as email.
Added test cases from the bug report to validate, such input will not be
rendered anymore as email address.
---------
Co-authored-by: wxiaoguang
email@domain@domain.com
`) + + // match GitHub behavior + test(`"info@gitea.com"`, ``) + // Test that should *not* be turned into email links - test( - "\"info@gitea.com\"", - `"info@gitea.com"
`) test( "/home/gitea/mailstore/info@gitea/com", `/home/gitea/mailstore/info@gitea/com
`) test( "git@try.gitea.io:go-gitea/gitea.git", `git@try.gitea.io:go-gitea/gitea.git
`) + test( + "https://foo:bar@gitea.io", + ``) test( "gitea@3", `gitea@3
`) test( "gitea@gmail.c", `gitea@gmail.c
`) - test( - "email@domain@domain.com", - `email@domain@domain.com
`) test( "email@domain..com", `email@domain..com
`) + + cases := []struct { + input, expected string + }{ + // match GitHub behavior + {"?a@d.zz", ``}, + {"*a@d.zz", ``}, + {"~a@d.zz", ``}, + + // the following cases don't match GitHub behavior, but they are valid email addresses ... + // maybe we should reduce the candidate characters for the "name" part in the future + {"a*a@d.zz", ``}, + {"a~a@d.zz", ``}, + } + for _, c := range cases { + test(c.input, c.expected) + } } func TestRender_emoji(t *testing.T) { -- cgit v1.2.3