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

CSS Modules build output hash not escaped #36673

Closed
2 tasks done
Noam-Bendelac opened this issue Sep 23, 2022 · 0 comments · Fixed by #36701
Closed
2 tasks done

CSS Modules build output hash not escaped #36673

Noam-Bendelac opened this issue Sep 23, 2022 · 0 comments · Fixed by #36701
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@Noam-Bendelac
Copy link

Preliminary Checks

Description

When a CSS Module hash of a class name contains certain characters like +, it doesn't always get escaped correctly. The code

@value classA from "./A.module.css";
@value print from "./A.module.css";

.classA .classB {
  color: red;
}

.print .classB {
  color: red;
}

Compiles into:

.A-module--classA--y8IDI {
}

.A-module--print--24b\+W {
}

.A-module--classA--y8IDI .B-module--classB--oWRdE {
  color: red;
}

.A-module--print--24b+W .B-module--classB--oWRdE {
  color: red;
}

.A-module--print--24b\+W is correctly escaped. .A-module--print--24b+W gets parsed as .A-module--print--24b + W because of the lack of escape character. Other class names whose hashes don't contain + work fine. If this is an issue with an external library Gatsby uses, where should I file that bug?

Reproduction Link

https://codesandbox.io/s/brave-grass-7fx9gn

Steps to Reproduce

  1. Write css module code as in the CodeSandbox, where an imported class is used as an ancestor in a css selector.
  2. Different class names will have different hashes. If the hash contains a + symbol, the generated css will be broken.

Expected Result

The generated code should escape the class name every time:

.A-module--print--24b\+W {
}

.A-module--print--24b\+W .B-module--classB--oWRdE {
  color: red;
}

Actual Result

The generated code does not escape the class name if used as an ancestor:

.A-module--print--24b\+W {
}

.A-module--print--24b+W .B-module--classB--oWRdE {
  color: red;
}

Environment

System:
    OS: Linux 5.13 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 14.19.3 - ~/.nvm/versions/node/v14.19.3/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v14.19.3/bin/yarn
    npm: 6.14.17 - ~/.nvm/versions/node/v14.19.3/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    gatsby: ^4.23.1 => 4.23.1

Config Flags

No response

@Noam-Bendelac Noam-Bendelac added the type: bug An issue or pull request relating to a bug in Gatsby label Sep 23, 2022
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 23, 2022
@tyhopp tyhopp added status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants