Skip to content

Commit

Permalink
Rewrote require_https_src as an arg
Browse files Browse the repository at this point in the history
  • Loading branch information
bcampeau committed Mar 17, 2016
1 parent bf08e23 commit 195fdff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions includes/sanitizers/class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public function maybe_enforce_https_src( $src, $force_https = false ) {
$protocol = strtok( $src, ':' );
if ( 'https' !== $protocol ) {
// Check if https is required
$https_required = apply_filters( 'amp_require_https_src', false );
if ( true === $https_required ) {
if ( isset( $this->args['require_https_src'] ) && true === $this->args['require_https_src'] ) {
// Remove the src. Let the implementing class decide what do from here.
$src = '';
} elseif ( false === $https_required && true === $force_https ) {
} elseif ( ( ! isset( $this->args['require_https_src'] ) || false === $this->args['require_https_src'] )
&& true === $force_https ) {
// Don't remove the src, but force https instead
$src = set_url_scheme( $src, 'https' );
}
Expand Down
6 changes: 3 additions & 3 deletions tests/test-amp-audio-converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public function test__https_required() {
$source = '<audio width="400" height="300" src="http://example.com/audio/file.ogg"></audio>';
$expected = '';

add_filter( 'amp_require_https_src', '__return_true' );

$dom = AMP_DOM_Utils::get_dom_from_content( $source );
$sanitizer = new AMP_Audio_Sanitizer( $dom );
$sanitizer = new AMP_Audio_Sanitizer( $dom, array(
'require_https_src' => true,
) );
$sanitizer->sanitize();

$content = AMP_DOM_Utils::get_content_from_dom( $dom );
Expand Down
7 changes: 4 additions & 3 deletions tests/test-amp-iframe-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ public function test__https_required() {
$source = '<iframe src="http://example.com/embed/132886713"></iframe>';
$expected = '';

add_filter( 'amp_require_https_src', '__return_true' );

$dom = AMP_DOM_Utils::get_dom_from_content( $source );
$sanitizer = new AMP_Iframe_Sanitizer( $dom );
$sanitizer = new AMP_Iframe_Sanitizer( $dom, array(
'add_placeholder' => true,
'require_https_src' => true,
) );
$sanitizer->sanitize();

$content = AMP_DOM_Utils::get_content_from_dom( $dom );
Expand Down
6 changes: 3 additions & 3 deletions tests/test-amp-video-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public function test__https_required() {
$source = '<video width="300" height="300" src="http://example.com/video.mp4"></video>';
$expected = '';

add_filter( 'amp_require_https_src', '__return_true' );

$dom = AMP_DOM_Utils::get_dom_from_content( $source );
$sanitizer = new AMP_Video_Sanitizer( $dom );
$sanitizer = new AMP_Video_Sanitizer( $dom, array(
'require_https_src' => true,
) );
$sanitizer->sanitize();

$content = AMP_DOM_Utils::get_content_from_dom( $dom );
Expand Down

0 comments on commit 195fdff

Please sign in to comment.