FILTER_VALIDATE_URL returns false when underscore present in URL
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code:
<?php
var_dump(filter_var('https://sub_domain.example.com', FILTER_VALIDATE_URL));
var_dump(filter_var('https://ex_ample.com', FILTER_VALIDATE_URL));
Resulted in this output:
bool(false)
bool(false)
But I expected this output instead:
string(30) "https://sub_domain.example.com"
string(20) "https://ex_ample.com"
The underscore is a valid character according to the RFC 2396 section 2.3:
Unreserved Characters
Data characters that are allowed in a URI but do not have a reserved
purpose are called unreserved. These include upper and lower case
letters, decimal digits, and a limited set of punctuation marks and
symbols.unreserved = alphanum | mark mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"Unreserved characters can be escaped without changing the semantics
of the URI, but this should not be done unless the URI is being used
in a context that does not allow the unescaped character to appear.
But this filter fails if a underscore is present in the domain or subdomain portion of the URL.
This RFC is superseded by RFC 3986, but the underscore is still in the unreserved characters:
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
PHP Version
PHP 8.4.4
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先重现 issue 中所示的使用 FILTER_VALIDATE_URL 的 filter_var() 调用,然后跟踪 php-src 中的 URL 验证实现。将主机和子域组件中下划线的处理方式与所引用的 RFC 章节进行比较。当文档中的示例产生预期的验证结果,并且相关测试覆盖了这一行为时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100