litespeedtech / litespeedtech/lscache_wp

Issue with inline `<style>` CSS optimization when CSS contains `<` character

Open
#605 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
257
Forks
123
PR merge metrics
No merged PRs in 30d

Description

I've encountered an issue with the inline CSS optimization feature of the LiteSpeed Cache plugin. It appears that the plugin's CSS optimization process is not handling inline `` tags correctly when the CSS contains the `<` character, such as in CSS `@property` syntax.

**Issue Description:**
The inline CSS within `<style>` tags that include CSS properties with syntax like `@property --image-title-bg{syntax:'<color>'; ...}` or `list-style-image: url('data:image/svg+xml;utf8,<svg xmlns...` are not being optimized to all css in `<style>`. It seems that the `<` character is causing the regex pattern used for matching and optimizing inline CSS to terminate prematurely.

**Actual Behavior:**
The inline CSS is not optimized, and the CSS content after the `<` character seems to be ignored by the optimization process.

I tried to change the matching code to the following code, and it can be matched for the time being. I hope you can help me update to solve the problem.

```php
preg_match_all('#<link ([^>]+)/?>|<style([^>]*)>((?:(?!).)*)#isU', $content, $matches, PREG_SET_ORDER);
```

I hope this information is helpful for diagnosing and resolving the issue. Please let me know if you need any further details or if I can assist in any way.

Thank you.

Contributor guide

No contributing guide indexed for this repository

Research direction

No file or test is named. Start by locating the inline CSS optimization entry point and its regex-based matching logic, then reproduce the issue with the shown @property and data SVG examples. Done means inline style content after a < character is optimized completely, with a regression test covering these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, php
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.