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

fix purgecss-from-pug not handle class attributes with multiple values correctly #677 #678

Merged
merged 1 commit into from
May 31, 2021

Conversation

Nauja
Copy link
Contributor

@Nauja Nauja commented May 19, 2021

Proposed changes

Replace token.val in purgecss-from-pug by ...token.val.split(" ") as done in purgecss-from-html to correctly handle class attributes with multiple values.

      case "tag":
      case "id":
      case "class":
-       selectors.push(token.val);
+       selectors.push(...token.val.split(" "));
        break;
      case "attribute":
        if (token.name === "class" || token.name === "id") {
          selectors.push(
-           token.mustEscape ? token.val.replace(/"/g, "") : token.val
+           ...(token.mustEscape ? token.val.replace(/"/g, "") : token.val).split(" ")
          );
        }
        break;

Also complete the unittest for purgecss-from-pug to demonstrate that multiple classes are correctly handled.

See bug #677

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

I am fairly new to purgecss, but clearly all CSS classes are not correctly extracted from .pug files and this is related to purgecss-from-pug treating a class attribute with multiple values as a single value as shown in the bug report. When checking the difference with purgecss-from-html, we can see that purgecss-from-pug extract classes with token.val while purgecss-from-html do something like val.split(" ").

@Ffloriel
Copy link
Member

Thanks!

@Ffloriel Ffloriel merged commit ba6285d into FullHuman:master May 31, 2021
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

Successfully merging this pull request may close these issues.

2 participants