Formating of error messages will fail for some rules if input is invalid UTF-8
还没有人认领这个 Issue。
评估
调研方向
Start by reproducing the Regex rule example with the invalid UTF-8 value "\x80", then trace the error-message formatting path that passes the value to IntlMessageFormatter::format(). Verify the fix by confirming that the result is formatted as "Field not valid." rather than returning the unformatted template, and add coverage for the invalid input if the existing test structure provides a suitable place.
由索引模型根据 Issue 内容生成。
描述
Description
If a value provided to validation rule is incorrect UTF-8,
then formatting of error messages for some rules will fail and original template message will be returned, without formatting.
For example, rule:
'field' => new Regex(
pattern: '/^abc$/u',
),
input field's value: "\x80" (it is invalid UTF-8)
result error: "{Property} not valid.", instead of "Field not valid."
This happens because for some rules value is passed to formatting along with other parameters:
['property' => ..., 'Property' => ..., 'value' => ...]
IntlMessageFormatter::format() fails to format it and returns false, and not formatted message used as fallback,
it fails because underlying intl ext (ICU library) strictly requires all incoming payload text to be valid UTF-8 or UTF-16
But error message should not be corrupted because of user input, value can be sanitized like this:
mb_substitute_character(0xFFFD);
$clean = mb_convert_encoding($dirty, 'UTF-8', 'UTF-8');
0xFFFD is official Unicode Replacement Character: �
or function from intl ext can be used for same result,
it is better because mb_substitute_character() sets global state
$clean = UConverter::transcode($dirty, 'UTF-8', 'UTF-8');
https://www.php.net/manual/en/uconverter.transcode.php
If the input string contains a sequence of bytes which is not valid in the encoding specified by fromEncoding, they are replaced by Unicode code point U+FFFD (Replacement Character) before converting to toEncoding.
Package version
No response
PHP version
No response
- 主要语言
- PHP
- 星标
- 166
- 派生
- 47
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
yiisoft/validator 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
-
Dataset is not passed to context in StopOnError()可能已有人在做 @vjik 于 32 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 65/100
-
难度 3/5 1-2 天 新手友好度 68/100
-
难度 3/5 1-2 天 新手友好度 62/100
-
Make File size validation messages human-readable可能已有人在做 @samdark 于 145 天前认领。 未关闭type:bug
查看 yiisoft/validator 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
backdrop-contrib/print#58 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
laravel/nova-issues#7008 ·
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
FriendsOfFlarum/badges#20 ·
-
[Dashboard Redesign] Support and Documentation links should warn they'll be opened in another tab未关闭Module: dashboard type: enhancement
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复