Skip to content

Update style sanitizer approach#935

Merged
westonruter merged 7 commits intodevelopfrom
update/style-sanitizer-approach
Feb 7, 2018
Merged

Update style sanitizer approach#935
westonruter merged 7 commits intodevelopfrom
update/style-sanitizer-approach

Conversation

@westonruter
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

amedina commented Feb 6, 2018

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

@westonruter
Copy link
Copy Markdown
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
Copy Markdown
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