Repository navigation
Fix InputNumber validation for scientific notation values - #67988
Conversation
|
Thanks for your PR, @surya3655. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
661b4c0 to
e8ffc63
Compare
e8ffc63 to
749ed45
Compare
749ed45 to
4404b6a
Compare
…655/aspnetcore-main into 6326-incorrect-validation # Conflicts: # src/Components/Components/src/BindConverter.cs # src/Components/Components/test/BindConverterTest.cs
…nto 6326-incorrect-validation # Conflicts: # src/submodules/googletest
There was a problem hiding this comment.
Pull request overview
This PR updates Blazor’s binding/conversion pipeline so InputNumber<T> validation accepts floating-point values entered in scientific notation (for float, double, and their nullable variants), aligning behavior with common .NET parsing expectations and addressing #6326.
Changes:
- Updated
BindConverterfloat/double parsing to allow exponent notation while preserving prior numeric parsing behaviors. - Added
BindConverterregression tests for scientific notation, group separators, and invalid exponent inputs. - Added
InputNumber<double>/InputNumber<double?>validation regression tests covering scientific notation and empty inputs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Components/Web/test/Forms/InputNumberTest.cs | Adds InputNumber<double> / InputNumber<double?> validation regression tests for exponent notation and invalid inputs. |
| src/Components/Components/test/BindConverterTest.cs | Adds parsing regression tests for scientific notation, group separators, and invalid exponent formats. |
| src/Components/Components/src/BindConverter.cs | Expands float/double parsing styles to accept exponent notation during conversion. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Thanks, looks good. Could you please reduce the number of tests or variants? Let's just test one scenario with several inputs, no need to have the full coverage here |
|
@kotlarmilos Thanks for the feedback! I've refactored the test suite to follow your recommendation—consolidated BindConverterTest from 6 methods down to 3, reducing total test variants from 28 to 12 (57% reduction). All conversion scenarios are preserved in single focused tests using [Theory] with representative [InlineData] cases. Removed 2 redundant InputNumber tests since BindConverter already validates conversion logic, keeping 5 component-level tests intact. Both test projects pass successfully. |
Description
This change fixes validation behavior for floating-point values entered in scientific notation in Blazor binding.
Previously,
BindConverterparsedfloat,float?,double, anddouble?values usingNumberStyles.Number. That parsing style supports normal numeric values and group separators, but it does not allow exponent/scientific notation.Because of this, valid floating-point values such as the following were rejected by
InputNumber<T>validation:The validation error shown was similar to:
This update changes the parsing flow so that:
floatanddoublevalues support scientific notation.float?anddouble?values support scientific notation.NumberStyles.AllowThousands.The parsing style has been updated from:
to:
This ensures valid floating-point values written in exponent notation are accepted consistently with .NET floating-point parsing behavior.
Output
Before
After
Fix Details
Updated
BindConverterparsing for the following types:Changed
floatparsing from:to:
Changed
doubleparsing from:to:
Tests Added
Added regression coverage for:
doublescientific notation parsing.double?nullable empty/null behavior.InputNumber<double?>scientific notation and empty value behavior.InputNumber<double>invalid scientific notation validation behavior.Representative valid test values:
Representative invalid test values:
Notes
NumberStyles.Floatis required because it includes exponent/scientific notation support.NumberStyles.AllowThousandsis included to preserve existing parser-level support for group separators, such as:This change does not modify parsing behavior for integer or decimal types.
Fixes #6326.