Skip to content

Commit cf2976e

Browse files
committed
Fix NumberFormatter partial parse handling
Only accept NumberFormatter results when entire string is consumed. Prevents incorrect parsing when locale doesn't match input format.
1 parent 32c59c3 commit cf2976e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Fieldtypes/Range.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ protected function normalizeNumber($value)
107107
// Try locale-aware parsing first (requires intl extension)
108108
if (class_exists(\NumberFormatter::class)) {
109109
$formatter = new \NumberFormatter(app()->getLocale(), \NumberFormatter::DECIMAL);
110-
$parsed = $formatter->parse($value);
110+
$parsed = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
111111

112-
if ($parsed !== false) {
112+
// Only use parsed value if the entire string was consumed
113+
// This ensures we don't accept partial/incorrect parses
114+
if ($parsed !== false && $position === strlen($value)) {
113115
return $parsed;
114116
}
115117
}

0 commit comments

Comments
 (0)