Skip to content

Commit

Permalink
Convert head[profile] attribute to a link[rel=profile]
Browse files Browse the repository at this point in the history
Like Weston mentioned, that was invalid HTML5,
so convert it to a link[rel=profile].
  • Loading branch information
kienstra committed Jan 29, 2020
1 parent 6021df7 commit 0484342
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ public function loadHTML( $source, $options = 0 ) {
$this->deduplicate_tag( self::TAG_HEAD );
$this->deduplicate_tag( self::TAG_BODY );
$this->move_invalid_head_nodes_to_body();
$this->convert_head_profile_to_link();
}

return $success;
Expand Down Expand Up @@ -536,6 +537,23 @@ private function move_invalid_head_nodes_to_body() {
}
}

/**
* Converts a possible head[profile] attribute to link[rel=profile].
*
* The head[profile] attribute is only valid in HTML4, not HTML5.
* So if it exists, add it to the <head> as a link[rel=profile] and strip the attribute.
*/
private function convert_head_profile_to_link() {
$profile = $this->head->getAttribute( 'profile' );
if ( $profile ) {
$link = $this->createElement( 'link' );
$link->setAttribute( 'rel', 'profile' );
$link->setAttribute( 'href', $profile );
$this->head->appendChild( $link );
$this->head->removeAttribute( 'profile' );
}
}

/**
* Force all self-closing tags to have closing tags.
*
Expand Down
5 changes: 5 additions & 0 deletions tests/php/test-class-amp-dom-document.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ public function data_dom_document() {
'<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]--><!--[if IE 7]> <html class="lt-ie9 lt-ie8"> <![endif]--><!--[if IE 8]> <html class="lt-ie9"> <![endif]--><!--[if gt IE 8]><!--> <html class=""> <!--<![endif]--></html>',
'<!DOCTYPE html><html class="">' . $head . '<body></body></html>',
],
'link_attribute_in_head_converted_to_link' => [
'utf-8',
'<!DOCTYPE html><html><head profile="https://example.com"></head><body></body></html>',
'<!DOCTYPE html><html><head><meta charset="utf-8"><link rel="profile" href="https://example.com"></head><body></body></html>',
],
];
}

Expand Down

0 comments on commit 0484342

Please sign in to comment.