Skip to content

Commit 6fc3070

Browse files
committed
fixes #80 improve internal URL detection
1 parent a7ce26e commit 6fc3070

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

src/HTMLProcessor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,14 @@ public function isInternalLink( string $link ) : bool {
654654
return $link_host === parse_url( $domain, PHP_URL_HOST );
655655
}
656656

657+
$extension = pathinfo( $link, PATHINFO_EXTENSION );
658+
659+
if ( ! $extension ) {
660+
if ( substr( $link, -1 ) !== '/' ) {
661+
return false;
662+
}
663+
}
664+
657665
// match anything without a colon, comma or space ie favicon.ico, not mailto:, viewport
658666
if (
659667
( strpos( $link, ':' ) === false ) &&

tests/HTMLProcessorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,20 @@ public function processHTMLProvider() {
489489
$this->loadTestHTML( 'input_inline_style_processing' ),
490490
$this->loadTestHTML( 'output_inline_style_processing' ),
491491
],
492+
'preserves non-URI meta content values' => [
493+
false, // $remove_conditional_head_comments = false
494+
false, // $remove_html_comments = false
495+
false, // $remove_wp_links = false
496+
false, // $remove_wp_meta = false
497+
'', // $rewrite_rules = ''
498+
'https://mynewdomain.com', // $base_url
499+
'', // $selected_deployment_option = 'folder'
500+
'http://localhost:4444', // $wp_site_url
501+
'/tmp/', // $wp_uploads_path - temp write file during test while refactoring
502+
'http://localhost:4444/',
503+
$this->loadTestHTML( 'input_meta_contents' ),
504+
$this->loadTestHTML( 'output_meta_contents' ),
505+
],
492506
];
493507
}
494508
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html class="no-js" lang="en-US">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="twitter:card" content="summary">
6+
<title>Static HTML Output Testing &#8211; test html processer</title>
7+
</head>
8+
9+
<body>
10+
<p>Ohai there!</p>
11+
12+
<p>Meta content like "summery" shouldn't be detected as a URL</p>
13+
</body>
14+
</html>
15+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html class="no-js" lang="en-US">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="twitter:card" content="summary">
6+
<title>Static HTML Output Testing &ndash; test html processer</title>
7+
</head>
8+
9+
<body>
10+
<p>Ohai there!</p>
11+
12+
<p>Meta content like "summery" shouldn't be detected as a URL</p>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)