-
Notifications
You must be signed in to change notification settings - Fork 384
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
Sanitize entire HTML output when theme support is present #888
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
82c274b
Bumped version to 0.6-rc2
ThierryA 91ef386
Remove erroneous additional allowance of script[type=text/javascript]
westonruter a5629f9
Merge pull request #884 from Automattic/fix/script-additional-allowed…
a666289
Make add `get_dom` method to AMP_DOM_Utils
DavidCramer 70a444e
Sanitize the output-buffered HTML document response
westonruter eededf8
Lower-case tag param in is_self_closing_tag check; replace static met…
westonruter 876c22f
Introduce AMP_Content_Sanitizer::sanitize_document() to bypass saniti…
westonruter 8257cb0
Remove unused parameter and fix phpcs error
westonruter ef69f2d
Merge branch '0.6' of https://github.com/Automattic/amp-wp into add/o…
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,53 @@ public function test_is_paired_available() { | |
$this->assertTrue( is_search() ); | ||
$this->assertFalse( AMP_Theme_Support::is_paired_available() ); | ||
} | ||
|
||
/** | ||
* Test finish_output_buffering. | ||
* | ||
* @covers AMP_Theme_Support::finish_output_buffering() | ||
*/ | ||
public function test_finish_output_buffering() { | ||
add_theme_support( 'amp' ); | ||
AMP_Theme_Support::init(); | ||
ob_start(); | ||
?> | ||
<!DOCTYPE html> | ||
<html amp <?php language_attributes(); ?>> | ||
<head> | ||
<?php wp_head(); ?> | ||
<script data-head>document.write('TODO: This needs to be sanitized as well once.');</script> | ||
</head> | ||
<body> | ||
<img width="100" height="100" src="https://example.com/test.png"> | ||
<audio width="400" height="300" src="https://example.com/audios/myaudio.mp3"></audio> | ||
<amp-ad type="a9" | ||
width="300" | ||
height="250" | ||
data-aax_size="300x250" | ||
data-aax_pubname="test123" | ||
data-aax_src="302"></amp-ad> | ||
<?php wp_footer(); ?> | ||
</body> | ||
</html> | ||
<?php | ||
$original_html = trim( ob_get_clean() ); | ||
$sanitized_html = AMP_Theme_Support::finish_output_buffering( $original_html ); | ||
|
||
$this->assertContains( '<meta charset="utf-8">', $sanitized_html ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @westonruter @DavidCramer these tests could have a bit more coverage here. I believe it is ok to do that at a later stage since the other components sanitization (form etc.) are still WIP. |
||
$this->assertContains( '<meta name="viewport" content="width=device-width,minimum-scale=1">', $sanitized_html ); | ||
$this->assertContains( '<style amp-boilerplate>', $sanitized_html ); | ||
$this->assertContains( '<style amp-custom>', $sanitized_html ); | ||
$this->assertContains( '<script async src="https://cdn.ampproject.org/v0.js"', $sanitized_html ); // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript | ||
$this->assertContains( '<meta name="generator" content="AMP Plugin', $sanitized_html ); | ||
|
||
$this->assertNotContains( '<img', $sanitized_html ); | ||
$this->assertContains( '<amp-img', $sanitized_html ); | ||
|
||
$this->assertNotContains( '<audio', $sanitized_html ); | ||
$this->assertContains( '<amp-audio', $sanitized_html ); | ||
$this->assertContains( '<script async custom-element="amp-audio"', $sanitized_html ); | ||
|
||
$this->assertContains( '<script async custom-element="amp-ad"', $sanitized_html ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter
get_amp_component_scripts
doesn't require the argument anymore.