Skip to content

CSS adds spaces/line breaks in @import url #5014

Closed

Description

@kinkoazc

Prettier 1.14.2
Playground link

--parser css

Input:

@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,600,700,900);

Output:

@import url(
  https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,
  300,
  600,
  700,
  900
);

or

@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:400, 300, 600, 700, 900);

Expected behavior:

@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,600,700,900);

Activity

  1. changed the title [-]CSS adds space/line breaks in @import url[/-] [+]CSS adds spaces/line breaks in @import url[/+] on Aug 24, 2018
  2. added
    lang:css/scss/less
    on Aug 24, 2018
  3. kraklin commented on Sep 6, 2018

    @kraklin

    It looks like the bug was first introduced in version 1.13.0. Version 1.12.1 looks like it is working well - no spaces after , but version 1.13.0 starts adding spaces.

  4. alexander-akait commented on Nov 14, 2018

    @alexander-akait
    Member

    Problem in postcss-values-parser, package doesn't respect url spec and parse this as function with arguments, no ideas how it can be fixed, because in scss/less it can be argument, need more difficult logic in parser

  5. added a commit that references this issue on Dec 8, 2018
  6. crcarlo commented on Feb 26, 2019

    @crcarlo

    I'm facing the same problem and the only way I could work around this issue is to wrap URLs in quotes.

    @import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,600,700,900");

    but still, as stated here this is regular CSS syntax and should therefore be supported

  7. sebastianhaberey commented on Apr 22, 2019

    @sebastianhaberey

    +1 stumbled across this today. Thanks @crcarlo for your workaround.

  8. sgehrman commented on May 26, 2019

    @sgehrman

    Hit this today too. will add quotes.

  9. rhernandog commented on Jun 12, 2019

    @rhernandog

    Indeed keeps happening up to know

  10. robert-j-webb commented on May 24, 2020

    @robert-j-webb
    Contributor

    I'm going to see if I can fix this today. I'm thinking maybe just add a special case to avoid parsing the arguments to the url function?

    It may be better even to enforce always having URL quotes, as a style decision. I understand that it's regular CSS syntax but in my opinion, it's weird syntax.

  11. robert-j-webb commented on May 24, 2020

    @robert-j-webb
    Contributor

    No longer seeing this happening on master. We can close this out.

  12. robert-j-webb commented on May 24, 2020

    @robert-j-webb
    Contributor

    Ach nevermind this is still happening, I was checking incorrectly.

  13. added this to the 2.1 milestone on May 24, 2020
  14. robert-j-webb commented on May 24, 2020

    @robert-j-webb
    Contributor

    Digging into this further, the issue is postcss-values-parser is parsing the URL into separate functional groups, when really it should just leave the URL value alone.

  15. robert-j-webb commented on May 24, 2020

    @robert-j-webb
    Contributor

    I created an issue for this in post-css-values parser. shellscape/postcss-values-parser#117

    However it may be better to fix it here. I found this issue only in loose mode, which is somewhat WAI

  16. robert-j-webb commented on May 24, 2020

    @robert-j-webb
    Contributor

    I can't distinguish between: url(fbglyph:cross-outline , fig-white); and url(url.com/Prettier+Sans&size=500,400,300,1000,600);

    But this is quite an improvement, considering the URL mangling bug does cause prettier to break sass, sending out a PR now.

  17. added 3 commits that reference this issue on May 24, 2020
    2543b6f
    5d98db3
    1c5b0ef
  18. added a commit that references this issue on May 25, 2020
    dc760b0
  19. added
    locked-due-to-inactivity
    on Aug 28, 2020
  20. locked as resolved and limited conversation to collaborators on Aug 28, 2020
  21. 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-inactivity

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions