Repository navigation
fix end-of-input handling in CompositeFormat cursor helpers - #338
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #338 +/- ##
============================================
+ Coverage 86.54% 87.22% +0.68%
+ Complexity 9787 91 -9696
============================================
Files 532 499 -33
Lines 35516 33519 -1997
Branches 6194 5848 -346
============================================
- Hits 30738 29238 -1500
+ Misses 3518 3162 -356
+ Partials 1260 1119 -141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Observed on master with the default formats:
Malformed input is accepted here and becomes a wrong value instead of a MathParseException.
The root cause is two end-of-input mistakes in the CompositeFormat cursor helpers.
parseNextCharacterdecides whether it found a character by testingindex < nafter the post-increment, so a non-whitespace character in the last position is consumed but reported as 0, which ComplexFormat reads as "no imaginary part".parseAndIgnoreWhitespacealways rewinds by one, so at end of input it steps back onto the previous character; in RealMatrixFormat the row suffix}is then matched a second time as the matrix suffix.The fix tests the character itself in
parseNextCharacterand rewinds only when something was consumed.parseFixedstringpreviously refused any literal at end of input, and formats with an empty suffix only parsed because of the bogus rewind, so it now lets an empty literal match there. Existing error indices (e.g.testForgottenSuffix) are unchanged. This is separate from #326, which fixed special-value matching inparseNumber.Regression tests are in ComplexFormatAbstractTest and RealMatrixFormatAbstractTest and fail without the patch.
mvn -pl commons-math-legacypasses on JDK 21 (checkstyle, PMD, SpotBugs, tests).