Some csstidy declaration are not handle properly in ExtractStyleBlocks
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.4k
- Forks
- 361
- Avg merge
- 3d 41m
- Merged PRs (30d)
- 2
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ExtractStyleBlocks.php around lines 317-319 and trace how the IMPORTANT_COMMENT entry is transformed. Reproduce the example with class.csstidy_print.php around lines 352-355, then verify that ExtractStyleBlocks preserves the comment as a string and that csstidy no longer raises the rtrim() type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100