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

purgecss-from-pug doesn't handle class attribute with multiple values correctly #677

Closed
Nauja opened this issue May 19, 2021 · 0 comments
Closed

Comments

@Nauja
Copy link
Contributor

Nauja commented May 19, 2021

Describe the bug

Unlike purgecss-from-html, purgecss-from-pug treat a class attribute containing multiple values as a single value.

For example if you have a div with a single class:

div(class="one-class")

Then "one-class" is correctly extracted.

But if you have a div with multiple classes:

div(class="first-class second-class")

Then "first-class second-class" is extracted instead of ["first-class", "second-class"]

To Reproduce

Modify packages/purgecss-from-pug/__tests__/data.ts to have a div with multiple classes:

export const TEST_1_CONTENT = `
html
  head
    title It's just a test
  body
    div(class="test-container") Well
    div(class="test-footer" id="an-id") I see a div
    a(class="a-link" id="a-link" href="#") and a link
+   div(class="first-class second-class") This div has two classes
    input#blo.enabled(type="text" disabled)
`;

export const TEST_1_TAG = [
  "html",
  "head",
  "title",
  "body",
  "div",
  "a",
  "input",
];

export const TEST_1_CLASS = [
  "test-container",
  "test-footer",
  "a-link",
+ "first-class",
+ "second-class",
  "enabled",
];

Running npm run test you get:

 FAIL  packages/purgecss-from-pug/__tests__/index.test.ts
  ● purgePug › from a normal html document › finds classes selectors

    expect(received).toBe(expected) // Object.is equality

    Expected: true
    Received: false

      15 |       const received = purgePug(TEST_1_CONTENT);
      16 |       for (const item of TEST_1_CLASS) {
    > 17 |         expect(received.includes(item)).toBe(true);
         |                                         ^
      18 |       }
      19 |     });
      20 |

      at Object.<anonymous> (packages/purgecss-from-pug/__tests__/index.test.ts:17:41)

  ● purgePug › from a normal html document › finds all selectors

    expect(received).toBe(expected) // Object.is equality

    Expected: true
    Received: false

      30 |       const selectors = [...TEST_1_TAG, ...TEST_1_CLASS, ...TEST_1_ID];
      31 |       for (const item of selectors) {
    > 32 |         expect(received.includes(item)).toBe(true);
         |                                         ^
      33 |       }
      34 |     });
      35 |   });

      at Object.<anonymous> (packages/purgecss-from-pug/__tests__/index.test.ts:32:41)

Now change:

export const TEST_1_CONTENT = `
html
  head
    title It's just a test
  body
    div(class="test-container") Well
    div(class="test-footer" id="an-id") I see a div
    a(class="a-link" id="a-link" href="#") and a link
    div(class="first-class second-class") This div has two classes
    input#blo.enabled(type="text" disabled)
`;

export const TEST_1_TAG = [
  "html",
  "head",
  "title",
  "body",
  "div",
  "a",
  "input",
];

export const TEST_1_CLASS = [
  "test-container",
  "test-footer",
  "a-link",
- "first-class",
- "second-class",
+ "first-class second-class",
  "enabled",
];

And you get:

 PASS  packages/purgecss-from-pug/__tests__/index.test.ts

Expected behavior

purgecss-from-pug should handle class attributes with multiple values correctly as purgecss-from-html does.

Environment (please complete the following information):

  • OS: Windows 10
  • Package purgecss-from-pug
  • Version 4.0.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants