Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Formating of error messages will fail for some rules if input is invalid UTF-8

オープン
#825 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

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
スター
167
フォーク
47
平均マージ
1日 16時間
マージ済み PR(30日)
4

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

yiisoft/validator のほかの issue

yiisoft/validator の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。