Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

56 changes: 7 additions & 49 deletions includes/Checker/Checks/Plugin_Repo/File_Type_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,62 +375,20 @@ function ( $file ) use ( $plugin_path ) {
* @param array $files List of absolute file paths.
*/
protected function look_for_library_core_files( Check_Result $result, array $files ) {
// Known libraries that are part of WordPress core.
// https://meta.trac.wordpress.org/browser/sites/trunk/api.wordpress.org/public_html/core/credits/wp-59.php#L739 .
$look_known_libraries_core_services = array(
'(?<![\.|-])jquery(-[0-9|\.]*)?(\.slim)?(\.min)?\.js(?!\/)',
'jquery-ui(-[0-9|\.]*)?(\.slim)?(\.min)?\.js(?!\/)',
'jquery.color(\.slim)?(\.min)?\.js(?!\/)',
'jquery.ui.touch-punch(?!\/)',
'jquery.hoverintent(?!\/)',
'jquery.imgareaselect(?!\/)',
'jquery.hotkeys(?!\/)',
'jquery.ba-serializeobject(?!\/)',
'jquery.query-object(?!\/)',
'jquery.suggest(?!\/)',
'polyfill(\.min)?\.js(?!\/)',
'iris(\.min)?\.js(?!\/)',
'backbone(\.min)?\.js(?!\/)',
'clipboard(\.min)?\.js(?!\/)',
'closest(\.min)?\.js(?!\/)',
'codemirror(\.min)?\.js(?!\/)',
'formdata(\.min)?\.js(?!\/)',
'json2(\.min)?\.js(?!\/)',
'lodash(\.min)?\.js(?!\/)',
'masonry(\.pkgd)(\.min)?\.js(?!\/)',
'mediaelement-and-player(\.min)?\.js(?!\/)',
'moment(\.min)?\.js(?!\/)',
'plupload(\.full)(\.min)?\.js(?!\/)',
'thickbox(\.min)?\.js(?!\/)',
'twemoji(\.min)?\.js(?!\/)',
'underscore([\.|-]min)?\.js(?!\/)',
'moxie(\.min)?\.js(?!\/)',
'zxcvbn(\.min)?\.js(?!\/)',
'getid3\.php(?!\/)',
'pclzip\.lib\.php(?!\/)',
'PasswordHash\.php(?!\/)',
'PHPMailer\.php(?!\/)',
'SimplePie\.php(?!\/)',
);

$combined_pattern = '/(' . implode( ')|(', $look_known_libraries_core_services ) . ')/i';

$plugin_path = $result->plugin()->path();

$files = array_map(
function ( $file ) use ( $plugin_path ) {
return str_replace( $plugin_path, '', $file );
},
$files
);

$relative_files = array();
foreach ( $files as $file ) {
if ( preg_match( $combined_pattern, $file ) ) {
$relative_files[ $file ] = str_replace( $plugin_path, '', $file );
}

foreach ( $relative_files as $file => $relative_file ) {
if ( Core_Library_File_Signature_Checker::file_matches_core_library_signature( $file, $relative_file ) ) {
$this->add_result_error_for_file(
$result,
__( 'Library files that are already in the WordPress core are not permitted.', 'plugin-check' ),
'library_core_files',
$file,
$relative_file,
0,
0,
'',
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<?php

namespace PHPMailer\PHPMailer;

class PHPMailer {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*! clipboard.js v2.0.11 */
window.ClipboardJS = function ClipboardJS() {};
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// For testing purposes, this file is empty.
/*! jQuery JavaScript Library v3.7.1 | jquery.org/license */
window.jQuery = window.jQuery || {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Custom feature detection helper that happens to use a generic polyfill.js
* filename without bundling WordPress core's registered polyfill script.
*/
window.examplePluginPolyfill = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace ExamplePlugin\Mail;

class PHPMailer {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Plugin Name: Test Plugin File Type Library Core Files Without Errors
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Some plugin description.
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/plugins/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-plugin-file-type-library-core-without-errors
*
* @package test-plugin-file-type-library-core-without-errors
*/

/**
* Plugin folder contains files with core-library-like names that are not
* bundled copies of WordPress core libraries.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copies text to the clipboard using browser APIs.
*
* This is a custom helper and not a bundled copy of a third-party package.
*/
export function copyToClipboard( text ) {
return navigator.clipboard.writeText( text );
}
18 changes: 17 additions & 1 deletion tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function test_run_with_library_core_errors() {
$errors = $check_result->get_errors();

$this->assertNotEmpty( $errors );
$this->assertEquals( 2, $check_result->get_error_count() );
$this->assertEquals( 3, $check_result->get_error_count() );

// Check for core PHPMailer.
$this->assertArrayHasKey( 0, $errors['PHPMailer.php'] );
Expand All @@ -222,6 +222,22 @@ public function test_run_with_library_core_errors() {
$this->assertArrayHasKey( 0, $errors['jquery.js'] );
$this->assertArrayHasKey( 0, $errors['jquery.js'][0] );
$this->assertCount( 1, wp_list_filter( $errors['jquery.js'][0][0], array( 'code' => 'library_core_files' ) ) );

// Check for core ClipboardJS.
$this->assertArrayHasKey( 0, $errors['clipboard.js'] );
$this->assertArrayHasKey( 0, $errors['clipboard.js'][0] );
$this->assertCount( 1, wp_list_filter( $errors['clipboard.js'][0][0], array( 'code' => 'library_core_files' ) ) );
}

public function test_run_with_library_core_filename_false_positives() {
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-library-core-without-errors/load.php' );
$check_result = new Check_Result( $check_context );

$check = new File_Type_Check( File_Type_Check::TYPE_LIBRARY_CORE );
$check->run( $check_result );

$this->assertSame( 0, $check_result->get_error_count() );
$this->assertEmpty( $check_result->get_errors() );
}

public function test_run_with_composer_errors() {
Expand Down
Loading