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

[Bug]: cssnano misinterprets unquoted font name as color #1463

Closed
Invizory opened this issue Jan 27, 2023 · 0 comments · Fixed by #1464
Closed

[Bug]: cssnano misinterprets unquoted font name as color #1463

Invizory opened this issue Jan 27, 2023 · 0 comments · Fixed by #1464

Comments

@Invizory
Copy link
Contributor

Invizory commented Jan 27, 2023

Bug Description

Consider the following CSS (all irrelevant properties are omitted):

@font-face {
  src: local(Noto Sans Black);
}

Here, Black is misinterpreted by cssnano as the name of the color, resulting in:

@font-face{src:local(Noto Sans #000)}

However, if one quotes a font face name, the problem disappears:

@font-face {
  src: local("Noto Sans Black");
}

The above example minifies to:

@font-face{src:local("Noto Sans Black")}

However, according to CSS Fonts Module Level 3 W3C recommendation, quotes are optional:

The syntax for a <font-face-name> is a unique font face name enclosed by "local(" and ")". The name can optionally be enclosed in quotes. If unquoted, the unquoted font family name processing conventions apply; the name must be a sequence of identifiers separated by whitespace which is converted to a string by joining the identifiers together separated by a single space.

It looks like the bug originates from postcss-colormin, which tries to minify color names within too many contexts without limiting oneself to the contexts where only colors can appear.

Maybe it's a good idea to add the following test to cssnano/packages/postcss-colormin/test/index.js and make it pass:

test(
  'should not attempt to convert unquoted font names',
  passthroughCSS('@font-face{src:local(Noto Sans Black)}')
);

Expected behaviour

@font-face{src:local(Black Font Name)}

Steps to reproduce

Minify the stylesheet provided above with cssnano playground or latest (5.1.14) version of cssnano.

Version

5.1.14

Preset

default

Environment

System:
  OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
  CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  Memory: 2.37 GB / 15.40 GB
  Container: Yes
  Shell: 5.8.1 - /usr/bin/zsh
@Invizory Invizory changed the title [Bug]: cssnano misinterprets font name as color [Bug]: cssnano misinterprets unquoted font name as color Jan 27, 2023
Invizory added a commit to Invizory/cssnano that referenced this issue Jan 27, 2023
Invizory added a commit to Invizory/cssnano that referenced this issue Jan 27, 2023
Invizory added a commit to Invizory/cssnano that referenced this issue Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant