-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix overly permissive parsing after whitespace #59
Merged
robjtede
merged 4 commits into
bytesize-rs:master
from
sholderbach:err-on-repeated-numeric-part
Feb 9, 2025
Merged
Fix overly permissive parsing after whitespace #59
robjtede
merged 4 commits into
bytesize-rs:master
from
sholderbach:err-on-repeated-numeric-part
Feb 9, 2025
+6
−3
Conversation
This file contains 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
The way the parse was implemented accepted additional numeric characters or `.` after the first valid `f64` literal but ignored them. This permitted more strings that are invalid following a strict grammar for byte sizes and silently ignores the further symbols without error. ``` 1.0 ...KB 1.0 42.0 B ``` This change makes those illegal. `1 000 B` was also subject to the bad `skip_while` ignoring the following `000`. In this version of the fix whitespace is not accepted as a digit separator. So it will raise an error if the user doesn't explicitly strip the whitespace instead of reporting a wrong value.
Loading status checks…
More following the old choices of using `f64::from_str`
robjtede
approved these changes
Feb 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these test cases look sensible to fix, thanks 👍🏻
Merged
robjtede
added a commit
that referenced
this pull request
Feb 9, 2025
robjtede
added a commit
that referenced
this pull request
Feb 9, 2025
robjtede
added a commit
that referenced
this pull request
Feb 9, 2025
robjtede
added a commit
that referenced
this pull request
Feb 9, 2025
robjtede
added a commit
to Andrew15-5/bytesize
that referenced
this pull request
Feb 10, 2025
* Fix parsing logic after first whitespace The way the parse was implemented accepted additional numeric characters or `.` after the first valid `f64` literal but ignored them. This permitted more strings that are invalid following a strict grammar for byte sizes and silently ignores the further symbols without error. ``` 1.0 ...KB 1.0 42.0 B ``` This change makes those illegal. `1 000 B` was also subject to the bad `skip_while` ignoring the following `000`. In this version of the fix whitespace is not accepted as a digit separator. So it will raise an error if the user doesn't explicitly strip the whitespace instead of reporting a wrong value. * Add tests for invalid chars after whitespace * Add test documenting that whitespace is not a valid digit separator More following the old choices of using `f64::from_str` --------- Co-authored-by: Rob Ede <robjtede@icloud.com>
Thanks for your maintenance work! |
sholderbach
added a commit
to sholderbach/nushell
that referenced
this pull request
Feb 11, 2025
Closes nushell#14866 Incorporates bytesize-rs/bytesize#59 with bytesize version 1.3.1 Added test with invalid input that was silently ignored before
sholderbach
added a commit
to sholderbach/nushell
that referenced
this pull request
Feb 11, 2025
Closes nushell#14866 Incorporates bytesize-rs/bytesize#59 with bytesize version 1.3.1 Added test with invalid input that was silently ignored before
sholderbach
added a commit
to nushell/nushell
that referenced
this pull request
Feb 11, 2025
# Description Closes #14866 Incorporates bytesize-rs/bytesize#59 with bytesize version 1.3.1 # User-Facing Changes Now rejected strings ``` "1.3 1.3 kB" | into filesize "1 420 kB" | into filesize ``` # Tests + Formatting Added test with invalid input that was silently ignored before
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.
Fix parsing logic after first whitespace
The way the parse was implemented accepted additional numeric characters
or
.
after the first validf64
literal but ignored them.This permitted more strings than are invalid following a strict grammar
for byte sizes and silently ignores the further symbols without error.
This change makes those illegal.
1 000 B
was also subject to the badskip_while
ignoring thefollowing
000
. In this version of the fix whitespace is not acceptedas a digit separator. So it will raise an error if the user doesn't
explicitly strip the whitespace instead of reporting a wrong value.