[6.x]: Html::decode() does not decode '

クローズ 初心者向け
#19,828 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

CraftCms\Cms\Support\Html::decode() (src/support/Html.php) から始め、offLabel にアポストロフィを指定して FormFields::lightswitchFieldHtml をレンダリングし、問題を再現します。Yiisoft\Html 経由で Html::encode/encodeAttribute が \u0026apos; を生成する方法と比較し、Html サポートクラスの既存のユニットテスト(テスト内で Html::decode または htmlspecialchars_decode を検索)の中から、リグレッションケースを追加する場所を探します。完了の条件は、\u0026apos; が decode/re-encode を往復しても \u0026amp;apos; にならず、それがテストでカバーされていることです。

索引モデルが issue の本文から書いたものです。

説明

bug repo:cms
What happened?

A lightswitch field with an apostrophe:

{!! FormFields::lightswitchFieldHtml([
    'label' => 'Example Setting',
    'offLabel' => "Don't Save",
]) !!}

Renders the entity:

Don't Save Data

I haven't verified this but if AIs suggestion helps as a starting point:

  1. HTML5 attribute encoding: When the tag is first created, Yiisoft\Html\Html::encodeAttribute() encodes ' as ' (off-label="Don't Save").
  2. Missing ENT_HTML5 in Html::decode(): When Field modifies the tag to attach slot="input", it parses existing attributes and calls Html::decode(). Because Html::decode() uses PHP's default HTML 4.01 charset without ENT_HTML5, it ignores ' and leaves it undecoded.
  3. Double encoding: When the attributes are re-rendered, the & in ' is re-encoded to & (off-label="Don't Save").
  4. The browser parses ' into the literal string Don't Save, which the web component prints directly to the screen.

AI suggests a fix by adding ENT_HTML5 to CraftCms\Cms\Support\Html::decode():

 public static function decode(string $content): string
 {
-    return htmlspecialchars_decode($content, ENT_QUOTES);
+    return htmlspecialchars_decode($content, ENT_QUOTES | ENT_HTML5);
 }
Craft CMS version

6.0.0-alpha.19

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions
主要言語
PHP
スター
3.6k
フォーク
712
平均マージ
13時間 5分
マージ済み PR(30日)
328

環境構築

はじめの一歩

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

craftcms/cms のほかの issue

craftcms/cms の issue をすべて見る

似ている issue

PHP の issue をもっと見る

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

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