Skip to content

Commit

Permalink
Set required property value from the meta sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlon committed Jan 30, 2020
1 parent 939394a commit b257819
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions includes/sanitizers/class-amp-meta-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ protected function ensure_viewport_is_present() {
$width_found = false;

foreach ( $viewport_settings as $index => $viewport_setting ) {
list( $property, $value ) = array_map( 'trim', explode( '=', $viewport_setting ) );
if ( 'width' === $property ) {
list( $property, $value ) = explode( '=', $viewport_setting );
if ( 'width' === trim( $property ) ) {
if ( 'device-width' !== $value ) {
$viewport_settings[ $index ] = 'width=device-width';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ private function check_attr_spec_rule_value_properties( DOMElement $node, $attr_
// This would occur when there are trailing commas, for example.
continue;
}
$properties[ strtolower( trim( $pair_parts[0] ) ) ] = trim( $pair_parts[1] );
$properties[ strtolower( trim( $pair_parts[0] ) ) ] = $pair_parts[1];
}

$invalid_properties = array_diff( array_keys( $properties ), array_keys( $attr_spec_rule[ AMP_Rule_Spec::VALUE_PROPERTIES ] ) );
Expand Down
6 changes: 6 additions & 0 deletions tests/php/test-class-amp-meta-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public function get_data_for_sanitize() {
'<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"></head><body></body></html>',
],

// Set required viewport property value.
[
'<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width= device-width ,minimum-scale=1,initial-scale=1"></head><body></body></html>',
'<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"></head><body></body></html>',
],

// Remove extra commas.
[
'<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content=",width=device-width,,minimum-scale=1,initial-scale=1,"></head><body></body></html>',
Expand Down

0 comments on commit b257819

Please sign in to comment.