File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -349,9 +349,11 @@ final public function addHtml($child)
349349 * Appends plain-text string to element content.
350350 * @return static
351351 */
352- public function addText (string $ text )
352+ public function addText ($ text )
353353 {
354- $ text = htmlspecialchars ($ text , ENT_NOQUOTES , 'UTF-8 ' );
354+ if (!$ text instanceof self) {
355+ $ text = htmlspecialchars ((string ) $ text , ENT_NOQUOTES , 'UTF-8 ' );
356+ }
355357 return $ this ->insert (null , $ text );
356358 }
357359
Original file line number Diff line number Diff line change @@ -115,6 +115,18 @@ test(function () { // attributes escaping
115115test (function () { // setText vs. setHtml
116116 Assert::same ('<p>Hello &ndash; World</p> ' , (string ) Html::el ('p ' )->setText ('Hello – World ' ));
117117 Assert::same ('<p>Hello – World</p> ' , (string ) Html::el ('p ' )->setHtml ('Hello – World ' ));
118+
119+ Assert::same ('<p><br></p> ' , (string ) Html::el ('p ' )->setText (Html::el ('br ' )));
120+ Assert::same ('<p><br></p> ' , (string ) Html::el ('p ' )->setHtml (Html::el ('br ' )));
121+ });
122+
123+
124+ test (function () { // addText vs. addHtml
125+ Assert::same ('<p>Hello &ndash; World</p> ' , (string ) Html::el ('p ' )->addText ('Hello – World ' ));
126+ Assert::same ('<p>Hello – World</p> ' , (string ) Html::el ('p ' )->addHtml ('Hello – World ' ));
127+
128+ Assert::same ('<p><br></p> ' , (string ) Html::el ('p ' )->addText (Html::el ('br ' )));
129+ Assert::same ('<p><br></p> ' , (string ) Html::el ('p ' )->addHtml (Html::el ('br ' )));
118130});
119131
120132
You can’t perform that action at this time.
0 commit comments