Fix percent progress validation and parsing #5381
Merged
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.
Description
Current implementation
The progress settings for Set Minimum Progress and Set Maximum Progress have a special validation and parsing function which is too basic and quite broken.
Current implementation of the parser is the regex
"(%d+)%%"
- digits followed by a literal %, first such match in the string.Examples of broken parsing
-12%
parsed as 1212.34%
parsed as 3412.34 %
not parsedabcd 12% efgh
parsed as 1212%34
parsed as 12New implementation
Find and replace first instance of a literal%
with space (See 5th example for why not empty string). The rest of the work is offloaded to tonumber (which trims leading and trailing whitespace)Find the
%
at the end of the string with regex"%% *$"
. If it is found, the parsing is offloaded to tonumber on the substring before the find.Fixed examples
-12%
parsed as -1212.34%
parsed as 12.3412.34 %
parsed as 12.34abcd 12% efgh
not parsed12%34
not parsed%12
not parsed12% abcd
not parsedType of change