From 4331710f9cf5def4ab4b3c4731586ac567736e04 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 13 Sep 2024 00:16:58 +0200 Subject: [PATCH 1/8] look for badly names --- .../Checks/Plugin_Repo/File_Type_Check.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index dfdc435d0..9f2cb2b9a 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -90,6 +90,9 @@ protected function check_files( Check_Result $result, array $files ) { if ( $this->flags & self::TYPE_APPLICATION ) { $this->look_for_application_files( $result, $files ); } + + // Check for badly named files. + $this->look_for_badly_named_files( $result, $files ); } /** @@ -244,6 +247,63 @@ protected function look_for_application_files( Check_Result $result, array $file } } + /** + * Looks for application files and amends the given result with an error if found. + * + * @since 1.0.0 + * + * @param Check_Result $result The check result to amend, including the plugin context to check. + * @param array $files List of absolute file paths. + */ + protected function look_for_badly_named_files( Check_Result $result, array $files ) { + $conflict_chars = array( '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=', '[', ']', '{', '}', ';', ':', '"', '\'', '<', '>', ',', '?', '/', '\\', '|', '`', '~' ); + + foreach ( $files as $file ) { + $badly_name = false; + if ( preg_match('/\s/', $file ) ) { + $badly_name = true; + } + + foreach ( $conflict_chars as $char ) { + if ( strpos( basename( $file ) , $char ) !== false ) { + $badly_name = true; + break; + } + } + + if ( $badly_name ) { + $this->add_result_error_for_file( + $result, + __( 'Badly named files are not permitted.', 'plugin-check' ), + 'badly_named_files', + $file, + 0, + 0, + '', + 8 + ); + } + } + + // Duplicated names. + $files = array_map( 'basename', $files ); + $files = array_map( 'strtolower', $files ); + $duplicated_files = array_unique( array_diff_assoc( $files, array_unique( $files ) ) ); + + if ( ! empty( $duplicated_files ) ) { + $this->add_result_error_for_file( + $result, + __( 'Duplicated file names are not permitted.', 'plugin-check' ), + 'duplicated_files', + implode( ', ', $duplicated_files ), + 0, + 0, + '', + 8 + ); + } + } + /** * Gets the description for the check. * From b99b68b142ea2554f774821cc1eb5e3c69b79505 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 13 Sep 2024 11:41:45 +0200 Subject: [PATCH 2/8] description --- includes/Checker/Checks/Plugin_Repo/File_Type_Check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index 9f2cb2b9a..e121dc4db 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -314,7 +314,7 @@ protected function look_for_badly_named_files( Check_Result $result, array $file * @return string Description. */ public function get_description(): string { - return __( 'Detects the usage of hidden and compressed files, VCS directories, and application files.', 'plugin-check' ); + return __( 'Detects the usage of hidden and compressed files, VCS directories, application files and badly named files.', 'plugin-check' ); } /** From f8dba9bf7bbd2f0b897767b28e6140812b08d469 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 13 Sep 2024 19:19:37 +0200 Subject: [PATCH 3/8] changed to preg_match --- .../Checker/Checks/Plugin_Repo/File_Type_Check.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index e121dc4db..0d5e9af4a 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -256,7 +256,7 @@ protected function look_for_application_files( Check_Result $result, array $file * @param array $files List of absolute file paths. */ protected function look_for_badly_named_files( Check_Result $result, array $files ) { - $conflict_chars = array( '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=', '[', ']', '{', '}', ';', ':', '"', '\'', '<', '>', ',', '?', '/', '\\', '|', '`', '~' ); + $conflict_chars = '!@#$%^&*()+=[]{};:"\'<>,?/\\|`~'; foreach ( $files as $file ) { $badly_name = false; @@ -264,12 +264,9 @@ protected function look_for_badly_named_files( Check_Result $result, array $file $badly_name = true; } - foreach ( $conflict_chars as $char ) { - if ( strpos( basename( $file ) , $char ) !== false ) { - $badly_name = true; - break; - } - } + if ( preg_match( '/[' . preg_quote( $conflict_chars, '/' ) . ']/', basename( $file ) ) ) { + $badly_name = true; + } if ( $badly_name ) { $this->add_result_error_for_file( From d955a00d30200d4992b49f7c7f7dedf2812feb4f Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sat, 14 Sep 2024 09:32:31 +0200 Subject: [PATCH 4/8] added tests for badly named files --- .../load.php | 17 +++++++++++++++++ .../plugin name.php | 3 +++ .../Checker/Checks/File_Type_Check_Tests.php | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/load.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/plugin name.php diff --git a/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/load.php new file mode 100644 index 000000000..3979dfdc7 --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/load.php @@ -0,0 +1,17 @@ +assertEmpty( $errors ); $this->assertSame( 0, $check_result->get_error_count() ); } + + public function test_run_with_badly_named_errors() { + // Test plugin without any forbidden file types. + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/load.php' ); + $check_result = new Check_Result( $check_context ); + + $check = new File_Type_Check(); + $check->run( $check_result ); + + $errors = $check_result->get_errors(); + + $this->assertNotEmpty( $errors ); + $this->assertArrayHasKey( 'plugin name.php', $errors ); + + // Check for invalid name error. + $this->assertArrayHasKey( 0, $errors['plugin name.php'] ); + $this->assertArrayHasKey( 0, $errors['plugin name.php'][0] ); + $this->assertCount( 1, wp_list_filter( $errors['plugin name.php'][0][0], array( 'code' => 'badly_named_files' ) ) ); + } } From 0b5b27da5f7404be4401a561831f7a095beadbbd Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sat, 14 Sep 2024 09:37:31 +0200 Subject: [PATCH 5/8] phpcs lint fixed --- composer.lock | 212 +++++++++--------- .../Checks/Plugin_Repo/File_Type_Check.php | 6 +- .../Checker/Checks/File_Type_Check_Tests.php | 2 +- 3 files changed, 110 insertions(+), 110 deletions(-) diff --git a/composer.lock b/composer.lock index e4f130017..c938d1f20 100644 --- a/composer.lock +++ b/composer.lock @@ -954,26 +954,26 @@ }, { "name": "composer/pcre", - "version": "2.2.0", + "version": "2.3.1", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "0e455b78ac53637929b29d5ab5bf3c978329c1eb" + "reference": "26859a860a7f140fc08422c3cc14ad9c2a287d79" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/0e455b78ac53637929b29d5ab5bf3c978329c1eb", - "reference": "0e455b78ac53637929b29d5ab5bf3c978329c1eb", + "url": "https://api.github.com/repos/composer/pcre/zipball/26859a860a7f140fc08422c3cc14ad9c2a287d79", + "reference": "26859a860a7f140fc08422c3cc14ad9c2a287d79", "shasum": "" }, "require": { "php": "^7.2 || ^8.0" }, "conflict": { - "phpstan/phpstan": "<1.11.8" + "phpstan/phpstan": "<1.11.10" }, "require-dev": { - "phpstan/phpstan": "^1.11.8", + "phpstan/phpstan": "^1.11.10", "phpstan/phpstan-strict-rules": "^1.1", "phpunit/phpunit": "^8 || ^9" }, @@ -1013,7 +1013,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/2.2.0" + "source": "https://github.com/composer/pcre/tree/2.3.1" }, "funding": [ { @@ -1029,7 +1029,7 @@ "type": "tidelift" } ], - "time": "2024-07-25T09:28:32+00:00" + "time": "2024-08-27T12:02:26+00:00" }, { "name": "composer/semver", @@ -1944,16 +1944,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.29.1", + "version": "1.30.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4" + "reference": "51b95ec8670af41009e2b2b56873bad96682413e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fcaefacf2d5c417e928405b71b400d4ce10daaf4", - "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/51b95ec8670af41009e2b2b56873bad96682413e", + "reference": "51b95ec8670af41009e2b2b56873bad96682413e", "shasum": "" }, "require": { @@ -1985,9 +1985,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.30.1" }, - "time": "2024-05-31T08:52:43+00:00" + "time": "2024-09-07T20:13:05+00:00" }, { "name": "phpstan/phpstan", @@ -3464,16 +3464,16 @@ }, { "name": "symfony/console", - "version": "v5.4.42", + "version": "v5.4.43", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "cef62396a0477e94fc52e87a17c6e5c32e226b7f" + "reference": "e86f8554de667c16dde8aeb89a3990cfde924df9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/cef62396a0477e94fc52e87a17c6e5c32e226b7f", - "reference": "cef62396a0477e94fc52e87a17c6e5c32e226b7f", + "url": "https://api.github.com/repos/symfony/console/zipball/e86f8554de667c16dde8aeb89a3990cfde924df9", + "reference": "e86f8554de667c16dde8aeb89a3990cfde924df9", "shasum": "" }, "require": { @@ -3543,7 +3543,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.42" + "source": "https://github.com/symfony/console/tree/v5.4.43" }, "funding": [ { @@ -3559,20 +3559,20 @@ "type": "tidelift" } ], - "time": "2024-07-26T12:21:55+00:00" + "time": "2024-08-13T16:31:56+00:00" }, { "name": "symfony/dependency-injection", - "version": "v5.4.42", + "version": "v5.4.43", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "c8409889fdbf48b99271930ea0ebcf3ee5e1ceae" + "reference": "8c946c5c1d1692d5378cb722060969730cebc96d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/c8409889fdbf48b99271930ea0ebcf3ee5e1ceae", - "reference": "c8409889fdbf48b99271930ea0ebcf3ee5e1ceae", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/8c946c5c1d1692d5378cb722060969730cebc96d", + "reference": "8c946c5c1d1692d5378cb722060969730cebc96d", "shasum": "" }, "require": { @@ -3632,7 +3632,7 @@ "description": "Allows you to standardize and centralize the way objects are constructed in your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/dependency-injection/tree/v5.4.42" + "source": "https://github.com/symfony/dependency-injection/tree/v5.4.43" }, "funding": [ { @@ -3648,7 +3648,7 @@ "type": "tidelift" } ], - "time": "2024-07-25T13:57:40+00:00" + "time": "2024-08-27T00:56:45+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3950,16 +3950,16 @@ }, { "name": "symfony/finder", - "version": "v5.4.42", + "version": "v5.4.43", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "0724c51fa067b198e36506d2864e09a52180998a" + "reference": "ae25a9145a900764158d439653d5630191155ca0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/0724c51fa067b198e36506d2864e09a52180998a", - "reference": "0724c51fa067b198e36506d2864e09a52180998a", + "url": "https://api.github.com/repos/symfony/finder/zipball/ae25a9145a900764158d439653d5630191155ca0", + "reference": "ae25a9145a900764158d439653d5630191155ca0", "shasum": "" }, "require": { @@ -3993,7 +3993,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v5.4.42" + "source": "https://github.com/symfony/finder/tree/v5.4.43" }, "funding": [ { @@ -4009,24 +4009,24 @@ "type": "tidelift" } ], - "time": "2024-07-22T08:53:29+00:00" + "time": "2024-08-13T14:03:51+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "0424dff1c58f028c451efff2045f5d92410bd540" + "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540", - "reference": "0424dff1c58f028c451efff2045f5d92410bd540", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638", + "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-ctype": "*" @@ -4072,7 +4072,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" }, "funding": [ { @@ -4088,24 +4088,24 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a" + "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/64647a7c30b2283f5d49b874d84a18fc22054b7a", - "reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", + "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "suggest": { "ext-intl": "For best performance" @@ -4150,7 +4150,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0" }, "funding": [ { @@ -4166,24 +4166,24 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb" + "reference": "3833d7255cc303546435cb650316bff708a1c75c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/a95281b0be0d9ab48050ebd988b967875cdb9fdb", - "reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c", + "reference": "3833d7255cc303546435cb650316bff708a1c75c", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "suggest": { "ext-intl": "For best performance" @@ -4231,7 +4231,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0" }, "funding": [ { @@ -4247,24 +4247,24 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" + "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", - "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341", + "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-mbstring": "*" @@ -4311,7 +4311,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" }, "funding": [ { @@ -4327,24 +4327,24 @@ "type": "tidelift" } ], - "time": "2024-06-19T12:30:46+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "ec444d3f3f6505bb28d11afa41e75faadebc10a1" + "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/ec444d3f3f6505bb28d11afa41e75faadebc10a1", - "reference": "ec444d3f3f6505bb28d11afa41e75faadebc10a1", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/0f68c03565dcaaf25a890667542e8bd75fe7e5bb", + "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "type": "library", "extra": { @@ -4387,7 +4387,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-php73/tree/v1.31.0" }, "funding": [ { @@ -4403,24 +4403,24 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "77fa7995ac1b21ab60769b7323d600a991a90433" + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433", - "reference": "77fa7995ac1b21ab60769b7323d600a991a90433", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "type": "library", "extra": { @@ -4467,7 +4467,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" }, "funding": [ { @@ -4483,24 +4483,24 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-php81", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php81.git", - "reference": "3fb075789fb91f9ad9af537c4012d523085bd5af" + "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/3fb075789fb91f9ad9af537c4012d523085bd5af", - "reference": "3fb075789fb91f9ad9af537c4012d523085bd5af", + "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", + "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "type": "library", "extra": { @@ -4543,7 +4543,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-php81/tree/v1.31.0" }, "funding": [ { @@ -4559,7 +4559,7 @@ "type": "tidelift" } ], - "time": "2024-06-19T12:30:46+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/service-contracts", @@ -4646,16 +4646,16 @@ }, { "name": "symfony/string", - "version": "v5.4.42", + "version": "v5.4.43", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "909cec913edea162a3b2836788228ad45fcab337" + "reference": "8be1d484951ff5ca995eaf8edcbcb8b9a5888450" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/909cec913edea162a3b2836788228ad45fcab337", - "reference": "909cec913edea162a3b2836788228ad45fcab337", + "url": "https://api.github.com/repos/symfony/string/zipball/8be1d484951ff5ca995eaf8edcbcb8b9a5888450", + "reference": "8be1d484951ff5ca995eaf8edcbcb8b9a5888450", "shasum": "" }, "require": { @@ -4712,7 +4712,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.42" + "source": "https://github.com/symfony/string/tree/v5.4.43" }, "funding": [ { @@ -4728,7 +4728,7 @@ "type": "tidelift" } ], - "time": "2024-07-20T18:38:32+00:00" + "time": "2024-08-01T10:24:28+00:00" }, { "name": "symfony/translation", @@ -4907,16 +4907,16 @@ }, { "name": "symfony/yaml", - "version": "v5.4.40", + "version": "v5.4.43", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "81cad0ceab3d61fe14fe941ff18a230ac9c80f83" + "reference": "62f96e1cfd4cf518882a36bfedcf1fe4093c1299" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/81cad0ceab3d61fe14fe941ff18a230ac9c80f83", - "reference": "81cad0ceab3d61fe14fe941ff18a230ac9c80f83", + "url": "https://api.github.com/repos/symfony/yaml/zipball/62f96e1cfd4cf518882a36bfedcf1fe4093c1299", + "reference": "62f96e1cfd4cf518882a36bfedcf1fe4093c1299", "shasum": "" }, "require": { @@ -4962,7 +4962,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v5.4.40" + "source": "https://github.com/symfony/yaml/tree/v5.4.43" }, "funding": [ { @@ -4978,7 +4978,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:33:22+00:00" + "time": "2024-08-11T17:40:32+00:00" }, { "name": "szepeviktor/phpstan-wordpress", @@ -5095,16 +5095,16 @@ }, { "name": "wp-cli/config-command", - "version": "v2.3.5", + "version": "v2.3.6", "source": { "type": "git", "url": "https://github.com/wp-cli/config-command.git", - "reference": "a4ae2c73a03706b7f5b8c74426a44b4df198352c" + "reference": "82a64ae0dbd8bc91e2bf0446666ae24650223775" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-cli/config-command/zipball/a4ae2c73a03706b7f5b8c74426a44b4df198352c", - "reference": "a4ae2c73a03706b7f5b8c74426a44b4df198352c", + "url": "https://api.github.com/repos/wp-cli/config-command/zipball/82a64ae0dbd8bc91e2bf0446666ae24650223775", + "reference": "82a64ae0dbd8bc91e2bf0446666ae24650223775", "shasum": "" }, "require": { @@ -5163,9 +5163,9 @@ "homepage": "https://github.com/wp-cli/config-command", "support": { "issues": "https://github.com/wp-cli/config-command/issues", - "source": "https://github.com/wp-cli/config-command/tree/v2.3.5" + "source": "https://github.com/wp-cli/config-command/tree/v2.3.6" }, - "time": "2024-07-22T10:31:46+00:00" + "time": "2024-08-05T13:34:06+00:00" }, { "name": "wp-cli/core-command", @@ -5703,16 +5703,16 @@ }, { "name": "yoast/phpunit-polyfills", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", - "reference": "4a088f125c970d6d6ea52c927f96fe39b330d0f1" + "reference": "562f449a2ec8ab92fe7b30d94da9622c7b1345fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/4a088f125c970d6d6ea52c927f96fe39b330d0f1", - "reference": "4a088f125c970d6d6ea52c927f96fe39b330d0f1", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/562f449a2ec8ab92fe7b30d94da9622c7b1345fe", + "reference": "562f449a2ec8ab92fe7b30d94da9622c7b1345fe", "shasum": "" }, "require": { @@ -5727,7 +5727,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.x-dev" + "dev-main": "3.x-dev" } }, "autoload": { @@ -5762,7 +5762,7 @@ "security": "https://github.com/Yoast/PHPUnit-Polyfills/security/policy", "source": "https://github.com/Yoast/PHPUnit-Polyfills" }, - "time": "2024-04-05T16:36:44+00:00" + "time": "2024-09-06T22:38:28+00:00" } ], "aliases": [], @@ -5780,5 +5780,5 @@ "platform-overrides": { "php": "7.2.24" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index 0d5e9af4a..a4b630a67 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -260,13 +260,13 @@ protected function look_for_badly_named_files( Check_Result $result, array $file foreach ( $files as $file ) { $badly_name = false; - if ( preg_match('/\s/', $file ) ) { + if ( preg_match( '/\s/', $file ) ) { $badly_name = true; } if ( preg_match( '/[' . preg_quote( $conflict_chars, '/' ) . ']/', basename( $file ) ) ) { - $badly_name = true; - } + $badly_name = true; + } if ( $badly_name ) { $this->add_result_error_for_file( diff --git a/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php index 1f9c073fc..d9a4ec61c 100644 --- a/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php @@ -108,7 +108,7 @@ public function test_run_with_badly_named_errors() { $check->run( $check_result ); $errors = $check_result->get_errors(); - + $this->assertNotEmpty( $errors ); $this->assertArrayHasKey( 'plugin name.php', $errors ); From d49c8ce07cb0312a733e1731a396f8aa36621db2 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sun, 15 Sep 2024 10:58:09 +0200 Subject: [PATCH 6/8] revert change --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index c938d1f20..87732424b 100644 --- a/composer.lock +++ b/composer.lock @@ -954,7 +954,7 @@ }, { "name": "composer/pcre", - "version": "2.3.1", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", From 88bd58cf7f9f6f98ada7cb58a57672b708cb055b Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sun, 15 Sep 2024 11:27:28 +0200 Subject: [PATCH 7/8] tests for special chars and spaces in directory --- .../badly directory/file.php | 2 ++ .../badly|file%name!@#$%^&*()+=[]{};:\"'<>,?|`~.php" | 3 +++ .../tests/Checker/Checks/File_Type_Check_Tests.php | 12 +++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly directory/file.php create mode 100644 "tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly|file%name!@#$%^&*()+=[]{};:\"'<>,?|`~.php" diff --git a/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly directory/file.php b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly directory/file.php new file mode 100644 index 000000000..5ebd0556e --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly directory/file.php @@ -0,0 +1,2 @@ +,?|`~.php" "b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly|file%name!@#$%^&*()+=[]{};:\"'<>,?|`~.php" new file mode 100644 index 000000000..92bee4abf --- /dev/null +++ "b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly|file%name!@#$%^&*()+=[]{};:\"'<>,?|`~.php" @@ -0,0 +1,3 @@ +get_errors(); $this->assertNotEmpty( $errors ); - $this->assertArrayHasKey( 'plugin name.php', $errors ); + $this->assertEquals( 3, $check_result->get_error_count() ); // Check for invalid name error. $this->assertArrayHasKey( 0, $errors['plugin name.php'] ); $this->assertArrayHasKey( 0, $errors['plugin name.php'][0] ); $this->assertCount( 1, wp_list_filter( $errors['plugin name.php'][0][0], array( 'code' => 'badly_named_files' ) ) ); + + // Badly named directory check. + $this->assertArrayHasKey( 0, $errors['badly directory/file.php'] ); + $this->assertArrayHasKey( 0, $errors['badly directory/file.php'][0] ); + $this->assertCount( 1, wp_list_filter( $errors['badly directory/file.php'][0][0], array( 'code' => 'badly_named_files' ) ) ); + + // Badly named file with special chars. + $this->assertArrayHasKey( 0, $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'] ); + $this->assertArrayHasKey( 0, $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'][0] ); + $this->assertCount( 1, wp_list_filter( $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'][0][0], array( 'code' => 'badly_named_files' ) ) ); } } From f1e18f8bfa839da87c621fe1deb306ccf5067429 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sun, 15 Sep 2024 11:35:11 +0200 Subject: [PATCH 8/8] duplicated file names test check --- .../folder1/class-filename.php | 3 +++ .../folder2/class-filename.php | 3 +++ .../phpunit/tests/Checker/Checks/File_Type_Check_Tests.php | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/folder1/class-filename.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/folder2/class-filename.php diff --git a/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/folder1/class-filename.php b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/folder1/class-filename.php new file mode 100644 index 000000000..371652721 --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/folder1/class-filename.php @@ -0,0 +1,3 @@ +get_errors(); $this->assertNotEmpty( $errors ); - $this->assertEquals( 3, $check_result->get_error_count() ); + $this->assertEquals( 4, $check_result->get_error_count() ); // Check for invalid name error. $this->assertArrayHasKey( 0, $errors['plugin name.php'] ); @@ -126,5 +126,10 @@ public function test_run_with_badly_named_errors() { $this->assertArrayHasKey( 0, $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'] ); $this->assertArrayHasKey( 0, $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'][0] ); $this->assertCount( 1, wp_list_filter( $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'][0][0], array( 'code' => 'badly_named_files' ) ) ); + + // Duplicated filenames. + $this->assertArrayHasKey( 0, $errors['class-filename.php'] ); + $this->assertArrayHasKey( 0, $errors['class-filename.php'][0] ); + $this->assertCount( 1, wp_list_filter( $errors['class-filename.php'][0][0], array( 'code' => 'duplicated_files' ) ) ); } }