为什么在RFC 822/Apache-Commons验证下接受TLD作为域?

发布于 2025-01-17 17:13:35 字数 1877 浏览 4 评论 0 原文

根据 Apache 文档,他们的电子邮件验证遵循 RFC 822 规范

EmailValidator 根据 RFC 822 标准提供电子邮件地址验证。 来源

但是,在本地运行一些测试时,我发现某些 TLD 被接受为域。

test@test      //invalid
[email protected]  //valid
test@com       //valid
test@comm      //invalid
test@amsterdam //valid
test@brussels  //valid

我想我在 RFC 中的某个地方读到 @ 是一个有效的电子邮件地址,但强烈建议不要使用(..因此应该被视为无效?)。所以我知道 test@test 无效,但 test@amsterdam 有效,因为 .amsterdam 是有效的 gTLD。

不确定这是否是一个错误或者是否是有意为之。从他们的实现和文档来看,尚不清楚什么应该是有效的,以及它是否 100% 符合 RFC 822 规范。


class Test {
    EmailValidator validator = EmailValidator.getInstance(false, true);

    @ParameterizedTest
    @ValueSource(strings = {
            "test@test",
            "[email protected]",
            "test@com",
            "test@comm",
            "test@amsterdam",
            "test@brussels"
    })
    void emails(String email) {
        System.out.printf("%-20s valid? %s%n", email, validator.isValid(email));
    }
}

我似乎也不明白 EmailValidator 构造函数执行以下操作

According to the Apache docs, their email validation respects the RFC 822 specification.

EmailValidator provides email address validation according to RFC 822 standards.
source

However when running some tests locally I found that some TLD's are accepted as a domain.

test@test      //invalid
[email protected]  //valid
test@com       //valid
test@comm      //invalid
test@amsterdam //valid
test@brussels  //valid

I thought I read somewhere in the RFC that <local>@<domain> is a valid e-mail address but highly discouraged to use (..and thus should be considered invalid?). So I get that test@test will not be valid, however test@amsterdam is, because .amsterdam is a valid gTLD.

Not sure if this is a bug or if this is intended. From their implementation and documentation it is unclear what should be valid, and if it is 100% comform the RFC 822 specification.


class Test {
    EmailValidator validator = EmailValidator.getInstance(false, true);

    @ParameterizedTest
    @ValueSource(strings = {
            "test@test",
            "[email protected]",
            "test@com",
            "test@comm",
            "test@amsterdam",
            "test@brussels"
    })
    void emails(String email) {
        System.out.printf("%-20s valid? %s%n", email, validator.isValid(email));
    }
}

What I also don't seem to get is what the parameters allowLocal and allowTld in the EmailValidator constructor do

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥︴琐丶欲为 2025-01-24 17:13:35

我会说这是意图的。您可以通过提供提到的参数来调整验证。

根据禁止无点域。

作为参数的解释词:

  • allocal - 将允许本地域,例如 mail@someNotexistingtld
  • allow> allowtld - 将允许顶级域,例如 mail@com

要具有真正准确的RFC822验证,您需要将同时设置为 true 。但是在现实生活中,我会说,在大多数情况下,它们将被省略或设置为 false

I would say this is intended. You can adjust validation to your by providing parameters you've mentioned.

According to https://www.icann.org/en/announcements/details/new-gtld-dotless-domain-names-prohibited-30-8-2013-en dotless domains are prohibited.

And as a word of explanation for parameters:

  • allowLocal - will allow local domains e.g mail@somenotexistingtld
  • allowTld - will allow top level domains e.g mail@com

To have truly accurate RFC822 validation you need set both to true. But in real life scenario I would say that in most of the cases they will be omitted or set to false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文