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:
oleibman
2024-01-09 19:29:00 -08:00
parent ae72efe43a
commit 5f232348d7
2 changed files with 8 additions and 2 deletions
@@ -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],
[' /', ' /'],
[' / ', ' / '],
];
}