litespeedtech / litespeedtech/lscache_wp
Problems with @charset in CSS
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 257
- Forks
- 123
- PR merge metrics
- No merged PRs in 30d
Description
I think I've found two small bugs.
In private function processAtRulesAndSelectors($css)
https://github.com/litespeedtech/lscache_wp/blob/master/litespeed-cache/lib/css_min.class.php#L701
// @charset handling
if (preg_match($this->charsetRegex, $css, $matches)) {
// Keep the first @charset at-rule found
$charset = $matches[0];
// Delete all @charset at-rules
$css = preg_replace($this->charsetRegex, '', $css);
}
But $matches is not defined in that function. So the first @charset is replaced
Secondly, in https://github.com/litespeedtech/lscache_wp/blob/master/litespeed-cache/inc/optimizer.class.php#L149
Has the regex
$data = preg_replace( '/@charset[^;]+;\\s*/', '', $data ) ;
This is incorrect. It should end ;\s*/ the double slash causes it to fail. See https://www.phpliveregex.com/p/ujR#tab-preg-replace for a demo
Basically, I think that @charset should not be removed from the start of a file. But I think these two functions don't work as intended.
Sorry if I haven't explained this well!
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 litespeed-cache/lib/css_min.class.php at processAtRulesAndSelectors($css), then inspect litespeed-cache/inc/optimizer.class.php around line 149. Reproduce both @charset cases with the CSS processing paths and confirm the intended handling from the issue; done means the two functions behave consistently without incorrectly removing or replacing @charset rules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100