diff --git a/LICENSE.BSD b/LICENSE.BSD index f45550d..4d44cc2 100644 --- a/LICENSE.BSD +++ b/LICENSE.BSD @@ -1,4 +1,4 @@ -BSD 2-Clause License +BSD 3-Clause License Copyright (c) 2019, Kenneth McCall All rights reserved. @@ -13,6 +13,10 @@ modification, are permitted provided that the following conditions are met: this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE diff --git a/README.md b/README.md index f6f6980..3779ec7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Packagist Version](https://img.shields.io/packagist/v/geeklab/toolbox)](https://packagist.org/packages/geeklab/toolbox) [![PHP Version](https://img.shields.io/packagist/dependency-v/geeklab/toolbox/php)](https://packagist.org/packages/geeklab/toolbox) [![PHPStan](https://img.shields.io/badge/PHPStan-level%2010-brightgreen)](https://phpstan.org/) +[![License: BSD-3-Clause](https://img.shields.io/badge/License-BSD--3--Clause-blue.svg)](LICENSE.BSD) Just some "utility" classes for PHP. diff --git a/composer.json b/composer.json index 5a2b463..09b2aaf 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "geeklab/toolbox", "description": "A collection of \"utility\" classes.", "type": "library", - "license": "GPL-3.0-or-later", + "license": "BSD-3-Clause", "authors": [ { "name": "EllisGL", diff --git a/src/ToolBox/Strings.php b/src/ToolBox/Strings.php index bbedda8..5624bfa 100644 --- a/src/ToolBox/Strings.php +++ b/src/ToolBox/Strings.php @@ -6,6 +6,7 @@ class Strings { /** * Does a string start with $needle? + * An empty $needle never matches. * * @param string $haystack * @param string $needle @@ -13,7 +14,8 @@ class Strings */ public static function beginsWith(string $haystack, string $needle): bool { - return (!empty($needle) && str_starts_with($haystack, $needle)); + // Compare with '' rather than empty(), since empty('0') is true and '0' is a valid needle. + return $needle !== '' && str_starts_with($haystack, $needle); } diff --git a/tests/unit/Strings_beingsWithTest.php b/tests/unit/Strings_beingsWithTest.php index 0774b00..21a116c 100644 --- a/tests/unit/Strings_beingsWithTest.php +++ b/tests/unit/Strings_beingsWithTest.php @@ -21,4 +21,19 @@ public function testItCantMatchBeginsWith(): void { $this->assertFalse(Strings::beginsWith($this->testStr, 'Sally')); } + + public function testItCanMatchZeroNeedle(): void + { + $this->assertTrue(Strings::beginsWith('012', '0')); + } + + public function testItCantMatchZeroNeedleElsewhere(): void + { + $this->assertFalse(Strings::beginsWith('102', '0')); + } + + public function testEmptyNeedleNeverMatches(): void + { + $this->assertFalse(Strings::beginsWith($this->testStr, '')); + } }