File tree 3 files changed +44
-1
lines changed
includes/Checker/Checks/Plugin_Repo
3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -485,7 +485,17 @@ public function run( Check_Result $result ) {
485
485
* @return bool true if the URL is valid, otherwise false.
486
486
*/
487
487
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 ;
489
499
}
490
500
491
501
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Plugin Name: Test Header fields with errors
4
+ * Plugin URI: https://example.com/sample-link
5
+ * Description: Here is a short description of the plugin.
6
+ * Requires at least: Recent version
7
+ * Requires PHP: Latest version
8
+ * Author: WordPress Performance Team
9
+ * Author URI: https://http://example.com/
10
+ * Text Domain: test-mismathed-textdomain-here
11
+ * Domain Path: /nonexistent-folder
12
+ * Network: random-value
13
+ * GitHub Plugin URI: johndoe/package
14
+ * Requires Plugins: Example Plugin, OtherPlugin
15
+ *
16
+ * @package test-plugin-header-fields-with-errors
17
+ */
Original file line number Diff line number Diff line change @@ -167,4 +167,20 @@ public function test_run_without_errors_requires_at_least_latest_version() {
167
167
168
168
$ this ->assertEmpty ( $ errors );
169
169
}
170
+
171
+ public function test_run_with_errors_duplicated_protocol_is_valid_url () {
172
+ $ check = new Plugin_Header_Fields_Check ();
173
+ $ check_context = new Check_Context ( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-header-fields-duplicated-protocol-with-errors/load.php ' );
174
+ $ check_result = new Check_Result ( $ check_context );
175
+
176
+ $ check ->run ( $ check_result );
177
+
178
+ $ errors = $ check_result ->get_errors ();
179
+
180
+ $ filtered_items = wp_list_filter ( $ errors ['load.php ' ][0 ][0 ], array ( 'code ' => 'plugin_header_invalid_author_uri ' ) );
181
+
182
+ $ this ->assertCount ( 1 , $ filtered_items );
183
+ $ this ->assertStringContainsString ( 'Author URI ' , $ filtered_items [1 ]['message ' ] );
184
+ $ this ->assertStringContainsString ( 'is not valid ' , $ filtered_items [1 ]['message ' ] );
185
+ }
170
186
}
You can’t perform that action at this time.
0 commit comments