Skip to content

Commit 14745ce

Browse files
committed
Improve url validation to check duplicate protocol
1 parent 9f771d0 commit 14745ce

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,17 @@ public function run( Check_Result $result ) {
485485
* @return bool true if the URL is valid, otherwise false.
486486
*/
487487
private function is_valid_url( $url ) {
488-
return filter_var( $url, FILTER_VALIDATE_URL ) === $url && str_starts_with( $url, 'http' );
488+
if ( filter_var( $url, FILTER_VALIDATE_URL ) !== $url || ! str_starts_with( $url, 'http' ) ) {
489+
return false;
490+
}
491+
492+
// Detect duplicated protocol (e.g., "https://http://example.com/").
493+
$parsed_url = wp_parse_url( $url );
494+
if ( isset( $parsed_url['scheme'] ) && str_contains( substr( $url, strlen( $parsed_url['scheme'] ) + 3 ), '://' ) ) {
495+
return false;
496+
}
497+
498+
return true;
489499
}
490500

491501
/**

0 commit comments

Comments
 (0)