Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some csstidy declaration are not handle properly in ExtractStyleBlocks #357

Open
Wolfrank1149 opened this issue Jan 6, 2023 · 1 comment

Comments

@Wolfrank1149
Copy link
Contributor

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.

  • ExtractStyleBlocks.php line 317-319 where IMPORTANT_COMMENT is transform
    $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.

  • class.csstidy_print.php line 352-355 where IMPORTANT_COMMENT is reuse in csstidy
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
Copy link
Owner

ezyang commented Jan 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants