question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Whitelisting doesn't keep a selector that ends in the html tag figure

See original GitHub issue

I’m having trouble with selector staying when I have it whitelisted. I tried diving into the code but I can’t quite figure out where the bug might be. Is there a list of HTML tags that purgeCSS goes off that it only allows? I’m trying to figure out why figure tag isn’t working properly. See below for an example:

Whitelist:

whitelistPatterns: [/vrabel/]

CSS:

/* This stays as expected */
.vrabel a {
    margin: 0;
}

/* This gets purged */
.vrabel figure {
    margin: 0;
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
danielcardoso5commented, Feb 16, 2018

This is also my main issue with purgecss. One use case is that I’m using Smooch messaging platform and a while ago they stopped providing a script file that I can pass to purgecss in order for it to look at the selectors defined there. In my code I’m overriding their styles by using something like #sk-holder and I want every selector that’s a child of #sk-holder to be kept by purge css, but they’re being stripped. It’s basically the same issue as @robertvrabel stated above.

I could think of a solution where you would pass a list of objects into whitelistPatterns, this objects would have two properties, the pattern itself and a boolean to keep child selectors. We could keep the current functionality by checking if the element in the whitelistPatterns array is a string or an object.

2reactions
robertvrabelcommented, Jan 14, 2018

@jsnanigans Ahh! So it has to match both. It would be really nice for it to work by matching the left most selector only, so you can easily whitelist everything under a particular selector. This would be really handy for when you’re pulling in packages.

The instance I had this problem is with magnific popup: https://github.com/dimsemenov/Magnific-Popup . They use a figure tag injected with javascript so it doesn’t actually exist in my scanned files. While I could add the figure tag somewhere as an example, it would much easier to just whitelistPatterns: /mfp-/and call it a day instead of worrying about .mfp figure.

Let me know if this is something that might be possible, or a feature you see as useful. Happy to try and help contribute as well if you can point me in the right direction 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow the "Limit allowed HTML tags" filter to also restrict HTML ...
Allow the "Limit allowed HTML tags" filter to also restrict HTML attributes, and only allow a small whitelist of attributes by default.
Read more >
Selectors - W3C
A type selector matches every instance of the element type in the document tree.
Read more >
visited - CSS: Cascading Style Sheets - MDN Web Docs
The :visited CSS pseudo-class applies once the link has been visited by the user. For privacy reasons, the styles that can be modified...
Read more >
The 30 CSS Selectors You Must Memorize - Code
If possible, first try to use a tag name, one of the new HTML5 elements, or even a pseudo-class ... Keep it simple,...
Read more >
HTML5 Security Cheatsheet
Avoid white-listing the "dirname" attribute in user generated content. The effects on existing forms are hard to predict and might cause privacy problems...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found