Skip to content

CSS: url(unquoted) is broken: Can be lowercased, normalized and broken across lines #2835

Description

@sampi

Prettier 1.7.0
Playground link

--parser postcss
--use-tabs

Input:

@font-face {
	font-family: 'Some Font';
	font-style: normal;
	font-weight: 300;
	src: local('Some Font'), url(data:application/font-woff;charset=utf-8;base64,ThisIsNormalBut/+0ThisIsLowerCased) format('woff');
}

Full example on Gist

Output:

@font-face {
	font-family: "Some Font";
	font-style: normal;
	font-weight: 300;
	src: local("Some Font"),
		url(data:application/font-woff;charset=utf-8;base64,ThisIsNormalBut/+0thisislowercased)
			format("woff");
}

Full example on Gist

Expected behavior:
Some characters are lowercased inside the base64-encoded @font-face url() rendering them useless.
Anything inside url() should be left untouched.

Activity

  1. lydell commented on Sep 15, 2017

    @lydell
    Member

    Oh, this is a tough one. The parser doesn't treat the whole url(...) as one single thing, but parses everything inside the parens. So it thinks that 0ThisIsLowerCased is the number 0 with the "ThisIsLowerCased" unit. There might be a workaround we can use, but the real fix is to add url-unquoted support to postcss-values-parser.

    To get you unblocked, add quotes:

    Prettier 1.7.0
    Playground link

    --parser postcss
    --use-tabs

    Input:

    @font-face {
    	font-family: 'Some Font';
    	font-style: normal;
    	font-weight: 300;
    	src: local('Some Font'), url('data:application/font-woff;charset=utf-8;base64,ThisIsNormalBut/+0ThisIsLowerCased') format('woff');
    }

    Output:

    @font-face {
    	font-family: "Some Font";
    	font-style: normal;
    	font-weight: 300;
    	src: local("Some Font"),
    		url("data:application/font-woff;charset=utf-8;base64,ThisIsNormalBut/+0ThisIsLowerCased")
    			format("woff");
    }
    
  2. added
    lang:css/scss/less
    scope:dependency
    on Sep 15, 2017
  3. sampi commented on Sep 15, 2017

    @sampi
    Author

    The quickest unblock was to place the affected files in .prettierignore, but the ' idea is better.

    Thanks!

  4. changed the title [-]Characters inside base64-encoded @font-face url() should not be converted to lowercase[/-] [+]CSS: `url(unquoted)` is broken: Can be lowercased, normalized and broken across lines[/+] on Sep 16, 2017
  5. alexander-akait commented on Jan 25, 2018

    @alexander-akait
    Member

    @lydell we can't use url-unquoted because we need parse url func inside to allow usage variables for css, less, scss - example url(var(--somevar))

  6. lydell commented on Jan 25, 2018

    @lydell
    Member

    As far as I know url(var(--somevar)) is equivalent to url("var(--somevar)") due to legacy reasons (url() is the only function where var() cannot be used). https://youtu.be/UQRSaG1hQ20?t=8m14s

  7. alexander-akait commented on Jan 26, 2018

    @alexander-akait
    Member

    @lydell how about:

    a {
      background-image: url(@var);
    }

    It is valid as unquoted url, but it is less variable, seems we should fix it in prettier

  8. lydell commented on Jan 26, 2018

    @lydell
    Member

    Yeah, I guess SCSS and Less have different rules for the url function. Difficult problem. I think I’m going to leave it up to you to come up with the best solution given what we have, that works for most people’s use cases :)

  9. alexander-akait commented on Jan 26, 2018

    @alexander-akait
    Member

    @lydell i try to find solution, maybe we can fix this for data: (PR exists), looks it is have equals rules for all preprocessors

  10. alexander-akait commented on Feb 2, 2018

    @alexander-akait
    Member

    Only problem with:

    a {
      background-image: url(/data/data/+0ThisIsLowerCased);
    }
  11. robert-j-webb commented on Feb 10, 2020

    @robert-j-webb
    Contributor

    This appears to be fixed: playground

  12. alexander-akait commented on Feb 10, 2020

    @alexander-akait
    Member

    Partial fixed

  13. added
    locked-due-to-inactivity
    on Aug 28, 2020
  14. locked as resolved and limited conversation to collaborators on Aug 28, 2020
  15. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:css/scss/lesslocked-due-to-inactivityscope:dependency

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions