You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: improve string validation to reject partial numeric strings
- Change from parseFloat() to Number() for string input validation
- Now properly throws HyperMathError for strings like "3.14abc" instead of parsing as 3.14
- Add comprehensive tests for processInput() method (10+ new test cases)
- Add tests for formatResult() method
- Update README and CHANGELOG to reflect validation behavior
- Test suite now includes 62 tests (all passing)
Copy file name to clipboardExpand all lines: CHANGELOG.md
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
8
+
## [Unreleased]
9
+
10
+
### Fixed
11
+
- 🐛 **String validation**: Changed from `parseFloat()` to `Number()` for string input validation to properly reject strings with trailing non-numeric characters (e.g., `"3.14abc"` now throws `HyperMathError` instead of being parsed as `3.14`)
12
+
13
+
### Changed
14
+
- 📝 **Documentation**: Updated README to clarify that string validation uses `Number()` and rejects partial numeric strings
15
+
16
+
### Testing
17
+
- ✅ Added comprehensive tests for `processInput()` method (10+ new test cases)
18
+
- ✅ Added comprehensive tests for `formatResult()` method
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -189,7 +189,7 @@ See [CHANGELOG.md](CHANGELOG.md) for complete migration guide.
189
189
-**Edge cases**:
190
190
-**Division by zero**: Throws `DivisionByZeroError` instead of returning 0
191
191
-**Invalid inputs**: Any null, undefined, or non-numeric string values will throw `HyperMathError`
192
-
-**String parsing**: String inputs are parsed using `parseFloat()`, so partial numeric strings like "123abc" will parse as 123
192
+
-**String parsing**: String inputs are validated using `Number()` to ensure the entire string is numeric. Strings with trailing non-numeric characters (e.g., `"123abc"`) will throw `HyperMathError`
193
193
-**Type safety**: TypeScript users benefit from full type definitions and the custom `HyperMathError` class for better error handling
0 commit comments