Skip to content

Commit

Permalink
Allow Apache license
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Jan 30, 2025
1 parent f43fc9e commit 21c97fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion includes/Traits/License_Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion tests/phpunit/tests/Traits/License_Utils_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
);
Expand Down Expand Up @@ -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 ),
Expand Down

0 comments on commit 21c97fc

Please sign in to comment.