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

Update style sanitizer approach #935

Merged
merged 7 commits into from Feb 7, 2018

Conversation

westonruter
Copy link
Member

  • Eliminate custom WP_Styles in favor of consolidating logic in AMP_Style_Sanitizer. This ensures that plugins that print link tags directly will automatically get them included. The same goes for style elements that a plugin prints.
  • External stylesheets and style elements now get concatenated in document order to ensure proper cascade.
  • Include CSS comment before each concatenated stylesheet indicating its source. This helps with debugging.
  • Run !important and overflow removal logic on inlined external stylesheets as well as style elements and style attributes.
  • Make sure that !important does not appear anywhere in CSS, including comments, as otherwise invalid and entire CSS gets stripped by whitelist sanitizer.
  • Stop concatenating CSS stylesheets to output if surpasses max size; show HTML comment containing the stylesheet URL that was excluded due to size. This helps with debugging.
  • Enforce that style sanitizer and whitelist sanitizer always run last.

Fixes #927. However, the longer-term fixes will need to be done as part of #930. This PR lays the groundwork for #930.

ThierryA
ThierryA previously approved these changes Feb 6, 2018
Copy link
Collaborator

@ThierryA ThierryA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome improvements!


$guessurl = site_url();
if ( ! $guessurl ) {
$guessurl = wp_guess_url();
Copy link
Collaborator

@ThierryA ThierryA Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know that function, nice!

@ThierryA ThierryA dismissed their stale review February 6, 2018 17:27

Travis Failed

@amedina
Copy link
Member

amedina commented Feb 6, 2018

@weston are we avoiding this: "Run !important removal logic" as discussed with @pbakaus?

@westonruter
Copy link
Member Author

@amedina Not yet. That will be addressed as part of #930. We can't do it yet because we don't have a CSS parser.

(I'll be squashing the commits once I identify why Travis is failing.)

@westonruter westonruter force-pushed the update/style-sanitizer-approach branch 11 times, most recently from 2ea228c to 7452b00 Compare February 7, 2018 00:22
@westonruter westonruter force-pushed the update/style-sanitizer-approach branch from 7452b00 to 4f61eef Compare February 7, 2018 00:31
@westonruter
Copy link
Member Author

Wow, that was one of the most obscure things I've ever had to debug.

@westonruter westonruter merged commit 215860d into develop Feb 7, 2018
@westonruter westonruter deleted the update/style-sanitizer-approach branch February 7, 2018 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove all instances of !important in CSS.
3 participants