diff --git a/src/ConverterHelpers.php b/src/ConverterHelpers.php index dc412c2..4c194c0 100644 --- a/src/ConverterHelpers.php +++ b/src/ConverterHelpers.php @@ -10,7 +10,12 @@ class ConverterHelpers{ */ public static function RangeToColumnArray(string $range): array{ $rangeArray = explode("-",$range); - if(count($rangeArray) !== 2){ + if(count($rangeArray) !== 2 + || strlen($rangeArray[0]) === 0 + || strlen($rangeArray[1]) === 0 + || !(strlen($rangeArray[0]) < strlen($rangeArray[1]) + || (strlen($rangeArray[0]) === strlen($rangeArray[1]) + && strcmp($rangeArray[0], $rangeArray[1]) <= 0))){ throw new MalformattedRangeStringException(); } diff --git a/tests/ConverterHelpersTest.php b/tests/ConverterHelpersTest.php index f86afe1..4b4e824 100644 --- a/tests/ConverterHelpersTest.php +++ b/tests/ConverterHelpersTest.php @@ -1,5 +1,6 @@ assertSame('Y|Z|AA|AB|AC', $res); } + public function testColumnRangeErrorOnWrongFormat(): void{ + $this->expectException(MalformattedRangeStringException::class); + $columns = ConverterHelpers::RangeToColumnArray("-AC"); + } + public function testColumnRangeErrorOnTwoLetterColumnFirst(): void{ + $this->expectException(MalformattedRangeStringException::class); + $columns = ConverterHelpers::RangeToColumnArray("AC-Y"); + } + public function testColumnRangeErrorOnHigherColumnFirst(): void{ + $this->expectException(MalformattedRangeStringException::class); + $columns = ConverterHelpers::RangeToColumnArray("Z-B"); + } } \ No newline at end of file