diff --git a/includes/Traits/License_Utils.php b/includes/Traits/License_Utils.php index 8ccbf3c1..c53bfbeb 100644 --- a/includes/Traits/License_Utils.php +++ b/includes/Traits/License_Utils.php @@ -54,6 +54,7 @@ protected function get_normalized_license( $license ) { $license = str_replace( 'GNU General Public License', 'GPL', $license ); $license = str_replace( ' version ', 'v', $license ); $license = preg_replace( '/GPL\s*[-|\.]*\s*[v]?([0-9])(\.[0])?/i', 'GPL$1', $license, 1 ); + $license = preg_replace( '/Apache.*?([0-9])(\.[0])?/i', 'Apache$1', $license ); $license = str_replace( '.', '', $license ); return $license; @@ -82,7 +83,7 @@ protected function is_license_valid_identifier( $license ) { * @return bool true if the license is GPL compatible, otherwise false. */ protected function is_license_gpl_compatible( $license ) { - $match = preg_match( '/GPL|GNU|MIT|FreeBSD|New BSD|BSD-3-Clause|BSD 3 Clause|OpenLDAP|Expat|Apache|MPL20|ISC/im', $license ); + $match = preg_match( '/GPL|GNU|MIT|FreeBSD|New BSD|BSD-3-Clause|BSD 3 Clause|OpenLDAP|Expat|Apache2|MPL20|ISC/im', $license ); return ( false === $match || 0 === $match ) ? false : true; } diff --git a/tests/phpunit/tests/Traits/License_Utils_Tests.php b/tests/phpunit/tests/Traits/License_Utils_Tests.php index 3a01809d..26e027cb 100644 --- a/tests/phpunit/tests/Traits/License_Utils_Tests.php +++ b/tests/phpunit/tests/Traits/License_Utils_Tests.php @@ -66,6 +66,13 @@ public function data_licenses_for_normalization() { array( 'GPL version 3', 'GPL3' ), array( 'GPL version 3 or later', 'GPL3' ), + array( 'Apache License, Version 2.0', 'Apache2' ), + array( 'Apache License 2.0', 'Apache2' ), + array( 'Apache License 2', 'Apache2' ), + array( 'Apache 2.0', 'Apache2' ), + array( 'Apache-2.0', 'Apache2' ), + array( 'Apache 2', 'Apache2' ), + array( 'MPL-1.0', 'MPL10' ), array( 'MPL-2.0', 'MPL20' ), ); @@ -97,7 +104,7 @@ public function data_license_gpl_compatibility() { array( 'GPL3', true ), array( 'MPL20', true ), array( 'MIT', true ), - array( 'Apache', true ), + array( 'Apache2', true ), array( 'FreeBSD', true ), array( 'New BSD', true ), array( 'BSD-3-Clause', true ),