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

Custom css URI functions are breaking #4644

Closed
vjeux opened this issue Jun 6, 2018 · 19 comments
Closed

Custom css URI functions are breaking #4644

vjeux opened this issue Jun 6, 2018 · 19 comments
Labels
lang:css/scss/less Issues affecting CSS, Less or SCSS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. priority:facebook blocker Issues that block Facebook from upgrading Prettier. (Facebook is a major Prettier supporter) type:bug Issues identifying ugly output, or a defect in the program

Comments

@vjeux
Copy link
Contributor

vjeux commented Jun 6, 2018

Prettier 1.13.4
Playground link

--parser css

Input:

div {
  background: -fb-datauri(/intern/images/org/product/default-image.png);
  background: -fb-datauri(/intern/images/organization/product/default-image.png);
}

Output:

div {
  background: -fb-datauri(/ intern/images/org/product/default-image.png);
  background: -fb-datauri(
    / intern/images/organization/product/default-image.png
  );
}

This is not urgent but would be nice to find a way not to put a space after the first /. I remember that we are doing some custom things for urls, maybe we can whitelist everything that ends with url/uri as a heuristic?

@vjeux vjeux added type:bug Issues identifying ugly output, or a defect in the program priority:facebook blocker Issues that block Facebook from upgrading Prettier. (Facebook is a major Prettier supporter) lang:css/scss/less Issues affecting CSS, Less or SCSS labels Jun 6, 2018
@alexander-akait
Copy link
Member

@vjeux because -fb-datauri is considered as not url function. But we can handle this as url.

@vjeux
Copy link
Contributor Author

vjeux commented Jun 6, 2018

I know it's fb-specific but would be great if we could :) Maybe do a more general heuristic like:

name.endsWith('url') || name.endsWith('uri')

instead of

name === 'uri'

@alexander-akait
Copy link
Member

@alexander-akait
Copy link
Member

alexander-akait commented Jun 6, 2018

@vjeux can break many code using endWiths, better use list of this functions

@vjeux
Copy link
Contributor Author

vjeux commented Jun 6, 2018

Sounds good, thanks for the pointer!

@lydell
Copy link
Member

lydell commented Jun 6, 2018

@vjeux If it's possible to quote the URLs you can use that as a workaround.

Prettier 1.13.4
Playground link

--parser css

Input:

div {
  background: -fb-datauri("/intern/images/org/product/default-image.png");
  background: -fb-datauri("/intern/images/organization/product/default-image.png");
}

Output:

div {
  background: -fb-datauri("/intern/images/org/product/default-image.png");
  background: -fb-datauri(
    "/intern/images/organization/product/default-image.png"
  );
}

@alexander-akait
Copy link
Member

alexander-akait commented Jun 6, 2018

Same problem #2835, try to fix both problem tommorow

@vjeux
Copy link
Contributor Author

vjeux commented Jun 6, 2018

I had some internal discussions and the current regex also doesn't support "" nor \n inside. Right now there's only a 100 occurrences so it's not a huge deal. There's a new infra to extract those pieces from CSS that's in the work that will support " but it's likely going to take some time to release.

I believe that we should find a way inside of prettier to not put a space after the / anyway, but in terms of priority it's pretty low and if we don't put any special handling inside of prettier we'll be fine, we can workaround on our end when it becomes an issue.

@dhruvdutt
Copy link

can break many code using endWiths, better use list of this functions

@evilebottnawi Can you please explain this by some example?

@alexander-akait
Copy link
Member

alexander-akait commented Aug 22, 2018

@dhruvdutt

.a {
  background: my-custom-scss-less-function-url('first_arg_is_not_url_but_can_have spaces and other strange-characters-+-*/');
}

@dhruvdutt
Copy link

Gotcha! So, what's the potential solution? Should we have a static array of strings like "-fb-datauri", "uri", "url"?

@alexander-akait
Copy link
Member

alexander-akait commented Aug 22, 2018

@dhruvdutt

  1. Switch on postcss-value-parse (url function have own algorithm for parsing)
  2. Use static array for url functions, but scss allow to redefine url function and it can break some edge cases like
@function url($arg) {
  return 'url';
}

a {
  background: url('same-other-strange-arg')
}

But some limitation for css is normal

@suchipi
Copy link
Member

suchipi commented Aug 23, 2018

@vjeux still relevant? Should we pursue this or are you fine using prettier ignore comments and closing this issue?

@alexander-akait
Copy link
Member

@suchipi no, we should fix it, it is not easy, but possible

@suchipi
Copy link
Member

suchipi commented Aug 23, 2018

I was gonna fix it really quick but didn't want to waste my time if it's not a problem for facebook anymore- vjeux indicated that they were changing the infra some around this

@vjeux
Copy link
Contributor Author

vjeux commented Aug 23, 2018

We could put everything with " and then allow for spaces around. But if it was fixed within prettier that would be great. It's not urgent though, it only affects 40 files that are barely touched.

@yajo

This comment has been minimized.

@fisker

This comment has been minimized.

@thorn0
Copy link
Member

thorn0 commented Feb 9, 2021

Fixed by #9966

@thorn0 thorn0 closed this as completed Feb 9, 2021
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label May 11, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:css/scss/less Issues affecting CSS, Less or SCSS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. priority:facebook blocker Issues that block Facebook from upgrading Prettier. (Facebook is a major Prettier supporter) type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

8 participants