为什么 Symfony2 URL 验证器会跳过 TLD? [英] Why does the Symfony2 URL validator skip the TLD?

查看:27
本文介绍了为什么 Symfony2 URL 验证器会跳过 TLD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在 Symfony2 中开发一个简单的 URL 缩短器 - 要求的一件事是输入必须是一个有效的 URL.

So, I'm developing a simple URL shortener in Symfony2 - one of the things that is required is the input must be a valid URL.

所以我已经设置了所有内容并且正在验证它,但是它没有验证 TLD!它将通过诸如A"之类的东西作为有效域!

So I've set everything up and it's being validated, but it doesn't validate the TLD! It will pass things through such as "A" as being a valid domain!

怎么回事?

推荐答案

您不仅要验证 TLD,还要验证 TLD 是否在公共后缀列表中:

You do not only want to validate the TLD, but also if the TLD is within the public suffix list:

另请参阅有关库列表的相关问题:从 URL 获取子域

Also please see a related question for a list of libraries: Get the subdomain from a URL

这篇关于为什么 Symfony2 URL 验证器会跳过 TLD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆