Skip to content

Commit

Permalink
fixes #80 improve internal URL detection
Browse files Browse the repository at this point in the history
  • Loading branch information
leonstafford committed Jun 9, 2020
1 parent a7ce26e commit 6fc3070
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/HTMLProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,14 @@ public function isInternalLink( string $link ) : bool {
return $link_host === parse_url( $domain, PHP_URL_HOST );
}

$extension = pathinfo( $link, PATHINFO_EXTENSION );

if ( ! $extension ) {
if ( substr( $link, -1 ) !== '/' ) {
return false;
}
}

// match anything without a colon, comma or space ie favicon.ico, not mailto:, viewport
if (
( strpos( $link, ':' ) === false ) &&
Expand Down
14 changes: 14 additions & 0 deletions tests/HTMLProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,20 @@ public function processHTMLProvider() {
$this->loadTestHTML( 'input_inline_style_processing' ),
$this->loadTestHTML( 'output_inline_style_processing' ),
],
'preserves non-URI meta content values' => [
false, // $remove_conditional_head_comments = false
false, // $remove_html_comments = false
false, // $remove_wp_links = false
false, // $remove_wp_meta = false
'', // $rewrite_rules = ''
'https://mynewdomain.com', // $base_url
'', // $selected_deployment_option = 'folder'
'http://localhost:4444', // $wp_site_url
'/tmp/', // $wp_uploads_path - temp write file during test while refactoring
'http://localhost:4444/',
$this->loadTestHTML( 'input_meta_contents' ),
$this->loadTestHTML( 'output_meta_contents' ),
],
];
}
}
15 changes: 15 additions & 0 deletions tests/data/HTMLProcessorTest/input_meta_contents.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html class="no-js" lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="twitter:card" content="summary">
<title>Static HTML Output Testing &#8211; test html processer</title>
</head>

<body>
<p>Ohai there!</p>

<p>Meta content like "summery" shouldn't be detected as a URL</p>
</body>
</html>

14 changes: 14 additions & 0 deletions tests/data/HTMLProcessorTest/output_meta_contents.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html class="no-js" lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="twitter:card" content="summary">
<title>Static HTML Output Testing &ndash; test html processer</title>
</head>

<body>
<p>Ohai there!</p>

<p>Meta content like "summery" shouldn't be detected as a URL</p>
</body>
</html>

0 comments on commit 6fc3070

Please sign in to comment.