ezyang / htmlpurifier

Standards compliant HTML filter written in PHP
http://htmlpurifier.org
GNU Lesser General Public License v2.1
3.03k stars 323 forks source link

Some csstidy declaration are not handle properly in ExtractStyleBlocks #357

Open Wolfrank1149 opened 1 year ago

Wolfrank1149 commented 1 year ago

In csstidy, IMPORTANT_COMMENT ($this->_tidy->css['!'] in ExtractStyleBlocks) are declaired as string. But, when it goes trough ExtractStyleBlocks, it is transformed in an empty array while it should stay a string.

    $new_decls[$selector] = $style;
}
$new_css[$k] = $new_decls;

The reason why it is reuse by csstidy where it expected to be a string and it cause an error because it is now an array.

if (isset($this->css['!'])) {
      $this->parser->_add_token(IMPORTANT_COMMENT, rtrim($this->css['!']), true);
      unset($this->css['!']);
}

Ex:

<style>
/*! important comment */
h1 {
  color: white;
  text-align: center;
}

/*! another important comment */
p {
  font-family: verdana;
  font-size: 20px;
}
</style>

After being parse by csstidy (ExtractStyleBlocks.php line 141), IMPORTANT_COMMENT looks like this: $this->_tidy->css['!'] = 'important comment\nanother important comment'

After being transform by ExtractStyleBlocks, IMPORTANT_COMMENT looks like this: $this->_tidy->css['!'] = []

It than cause an argument error rtrim(): Argument #1 ($string) must be of type string, array given when it is reuse by csstidy.

ezyang commented 1 year ago

Do you think you'd be able to submit a PR for this?