Skip to content

Commit

Permalink
Decode special chars such as >, & in selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Aug 7, 2023
1 parent 34c2311 commit 63778d5
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Style extends LessRuleset implements ValidHtml
/** @var ?string */
protected $nonce;

/** @var bool Set if html special chars needs to be decoded */
protected $decode = false;

public function getNonce(): ?string
{
return $this->nonce;
Expand Down Expand Up @@ -63,11 +66,44 @@ public function render(): string
$ruleset = $this;
}

return new HtmlElement(
$htmlElement = new HtmlElement(
'style',
(new Attributes())->addAttribute(new Attribute('nonce', $this->nonce)),
Text::create($ruleset->renderCss())
);

if ($this->getDecode()) {
$htmlElement = htmlspecialchars_decode(
$htmlElement,
ENT_COMPAT | ENT_SUBSTITUTE | ENT_HTML5
);
}

return $htmlElement;
}

/**
* Set whether the html special chars needs to be decoded
*
* @param bool $decode
*
* @return $this
*/
public function setDecode(bool $decode = false)
{
$this->decode = $decode;

return $this;
}

/**
* Get whether the html special chars needs to be decoded
*
* @return bool
*/
public function getDecode()
{
return $this->decode;
}

/**
Expand Down

0 comments on commit 63778d5

Please sign in to comment.