mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-14 20:16:34 +00:00
Advanced Value Binder False Positive Looking for Fractions
Fix #3861. Strings ending in `/` were inappropriately identifed as fractions. Fix regexp accordingly.
This commit is contained in:
@@ -43,9 +43,9 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder
|
||||
}
|
||||
|
||||
// Check for fractions
|
||||
if (preg_match('/^([+-]?)\s*(\d+)\s?\/\s*(\d+)$/', $value, $matches)) {
|
||||
if (preg_match('~^([+-]?)\s*(\d+)\s*/\s*(\d+)$~', $value, $matches)) {
|
||||
return $this->setProperFraction($matches, $cell);
|
||||
} elseif (preg_match('/^([+-]?)(\d*) +(\d*)\s?\/\s*(\d*)$/', $value, $matches)) {
|
||||
} elseif (preg_match('~^([+-]?)(\d+)\s+(\d+)\s*/\s*(\d+)$~', $value, $matches)) {
|
||||
return $this->setImproperFraction($matches, $cell);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,12 @@ class AdvancedValueBinderTest extends TestCase
|
||||
['1 16/20', 1.8],
|
||||
['12 20/100', 12.2],
|
||||
['-1 4/20', -1.2],
|
||||
['407 / ', '407 / '],
|
||||
['407 /', '407 /'],
|
||||
['407 3/', '407 3/'],
|
||||
['-407 /4', -101.75],
|
||||
[' /', ' /'],
|
||||
[' / ', ' / '],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user