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

Conditional comments around CSS style blocks are gone #146

Open
PHPGangsta opened this issue Aug 3, 2017 · 2 comments
Open

Conditional comments around CSS style blocks are gone #146

PHPGangsta opened this issue Aug 3, 2017 · 2 comments

Comments

@PHPGangsta
Copy link
Contributor

When using Filter.ExtractStyleBlocks to extract CSS style blocks, HTML conditional comments are removed, which leads to wrong looking HTML. I have this example code:

<head>
    <style>
        div {display: none;}
    </style>
    <!--[if IE 6]>
    <style>    
        div {display: block;}
    </style>
    <![endif]-->
</head>
<body>
<div>hi</div>
</body>
</html>```

In this case, the link should only be shown in IE 6.

The output of HTML is the following, which is correct:
<div>hi</div>

The corresponding CSS style blocks look like this:
```  array(2) {
    [0] =>
    string(18) "div {
display:none
}"
    [1] =>
    string(19) "div {
display:block
}"
  }

The information about the IE6 is gone, if I output both style blocks on the website, the div is always shown, because the conditional comment is gone.

At the moment I don't have a good idea how to fix this, I hope someone of you has an idea. The information is important and should not be lost.

@ezyang
Copy link
Owner

ezyang commented Aug 5, 2017

Hmm, the problem is likely because we regex out style blocks, so comment parsing is not in effect:

$html = preg_replace_callback('#<style(?:\s.*)?>(.*)<\/style>#isU', array($this, 'styleCallback'), $html);

in library/HTMLPurifier/Filter/ExtractStyleBlocks.php. If you swapped this out for something more clever that would probably solve the problem.

@Whip
Copy link

Whip commented Jul 20, 2021

Facing the same problem. Is there something that can be specified in HTML.AllowedComments to not filter this out?

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

3 participants