File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -77,12 +77,16 @@ public function __construct(string $path = '')
7777 *
7878 * @throws Exception
7979 */
80- public function setParam (string $ key , mixed $ value ): static
80+ public function setParam (string $ key , mixed $ value, bool $ escapeHtml = true ): static
8181 {
8282 if (\strpos ($ key , '. ' ) !== false ) {
8383 throw new Exception ('$key can \'t contain a dot "." character ' );
8484 }
8585
86+ if (is_string ($ value ) && $ escapeHtml ) {
87+ $ value = \htmlspecialchars ($ value , ENT_QUOTES , 'UTF-8 ' );
88+ }
89+
8690 $ this ->params [$ key ] = $ value ;
8791
8892 return $ this ;
Original file line number Diff line number Diff line change @@ -83,4 +83,10 @@ public function testCanFilterNewLinesToParagraphs()
8383 {
8484 $ this ->assertEquals ('<p>line1</p><p>line2</p> ' , $ this ->view ->print ("line1 \n\nline2 " , View::FILTER_NL2P ));
8585 }
86+
87+ public function testCanSetParamWithEscapedHtml ()
88+ {
89+ $ this ->view ->setParam ('key ' , '<html>value</html> ' );
90+ $ this ->assertEquals ('<html>value</html> ' , $ this ->view ->getParam ('key ' , 'default ' ));
91+ }
8692}
You can’t perform that action at this time.
0 commit comments