Fixed parsing of conditionals in COUNTIF functions
Conditional operators in the selection parameter of COUNTIF functions were not being parsed properly, causing evaluations of formulae with such functions to sometimes fail. Fixes #526 Closes #528
This commit is contained in:
		
							parent
							
								
									ed2185417e
								
							
						
					
					
						commit
						e3fb160f5f
					
				@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 | 
			
		||||
- Xlsx reader do not read rows and columns filtered out in readFilter at all - [#370](https://github.com/PHPOffice/PhpSpreadsheet/issues/370)
 | 
			
		||||
- Make newer Excel versions properly recalculate formulas on document open - [#456](https://github.com/PHPOffice/PhpSpreadsheet/issues/456)
 | 
			
		||||
- `Coordinate::extractAllCellReferencesInRange()` throws an exception for an invalid range – [#519](https://github.com/PHPOffice/PhpSpreadsheet/issues/519)
 | 
			
		||||
- Fixed parsing of conditionals in COUNTIF functions - [#526](https://github.com/PHPOffice/PhpSpreadsheet/issues/526)
 | 
			
		||||
 | 
			
		||||
## [1.2.1] - 2018-04-10
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -277,7 +277,7 @@ class Functions
 | 
			
		||||
 | 
			
		||||
            return '=' . $condition;
 | 
			
		||||
        }
 | 
			
		||||
        preg_match('/([<>=]+)(.*)/', $condition, $matches);
 | 
			
		||||
        preg_match('/(=|<[>=]?|>=?)(.*)/', $condition, $matches);
 | 
			
		||||
        list(, $operator, $operand) = $matches;
 | 
			
		||||
 | 
			
		||||
        if (!is_numeric($operand)) {
 | 
			
		||||
 | 
			
		||||
@ -307,4 +307,20 @@ class FunctionsTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        return require 'data/Calculation/Functions/ISFORMULA.php';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider providerIfCondition
 | 
			
		||||
     *
 | 
			
		||||
     * @param mixed $expectedResult
 | 
			
		||||
     */
 | 
			
		||||
    public function testIfCondition($expectedResult, ...$args)
 | 
			
		||||
    {
 | 
			
		||||
        $result = Functions::ifCondition(...$args);
 | 
			
		||||
        self::assertEquals($expectedResult, $result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function providerIfCondition()
 | 
			
		||||
    {
 | 
			
		||||
        return require 'data/Calculation/Functions/IF_CONDITION.php';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										36
									
								
								tests/data/Calculation/Functions/IF_CONDITION.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								tests/data/Calculation/Functions/IF_CONDITION.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
return [
 | 
			
		||||
    [
 | 
			
		||||
        '<"A"',
 | 
			
		||||
        '<A',
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
        '>"A"',
 | 
			
		||||
        '>A',
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
        '<="A"',
 | 
			
		||||
        '<=A',
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
        '>"A"',
 | 
			
		||||
        '>A',
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
        '>="A"',
 | 
			
		||||
        '>=A',
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
        '<>"A"',
 | 
			
		||||
        '<>A',
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
        '<"<A"',
 | 
			
		||||
        '<<A',
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
        '<>"< PLEASE SELECT >"',
 | 
			
		||||
        '<>< Please Select >',
 | 
			
		||||
    ],
 | 
			
		||||
];
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user