0

bbcode を解析するクラスを作成しましたが、「エスケープ」を使用すると問題が発生します (関数 chtml::encode は htmlspecialchars のラッパーです)。

MyBBcodeParser: http://snipt.org/srlo0

Case "BBcodeParser::toHtml($input, false)": Input: [b]hello[/b] <strong>hello2</strong> Output: <strong>hello</strong> <strong>hello2</strong> (太字を適用)

Case "BBcodeParser::toHtml($input, true)": Input: [b]hello[/b] <strong>hello2</strong> Output: &lt;strong&gt;hello&lt;/strong&gt;&amp;lt;strong&amp;gt;hello2&amp;lt;/strong&amp;gt;

2回目のケースからのダブルエスケープが理解できません...

4

1 に答える 1

2

入力で呼び出すBBcodeParser::toHtml($input, true)と、次のものが返されます。

<strong>hello</strong> &lt;strong&gt;hello2&lt;/strong&gt;

これは、CHtml::encodeが preg_replace の前に適用され、入力から HTML コードをエスケープしながら、BBcode からの後に生成された HTML コードをそのまま残しているためです (秒<strong>、 の周りのhello2)。

CHtml::encodeここで、「エスケープされた」BBcode の結果に再度適用すると、投稿したようになります (&lt;最初の強力な と&amp;lt;2 番目の に注意してください)。

&lt;strong&gt;hello&lt;/strong&gt;&amp;lt;strong&amp;gt;hello2&amp;lt;/strong&amp;gt;

最初のケースでは、エンコーディングがまったくないようです。

于 2011-12-27T18:47:49.887 に答える