-
Notifications
You must be signed in to change notification settings - Fork 247
Fix the issue that zero has been ignored #228
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
Conversation
| } | ||
| for (NSUInteger i = 0; i < zeros; ++i) { _operands.push_back(0.0); } | ||
|
|
||
| while ([scanner scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:NULL]) { } |
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.
why is there an empty while loop here? isn't this an infinite loop
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.
It's not an infinite loop. It will move the scanner to next char if the current char is a whitespace.
|
@arthurpazpicpay @kidd0717 thanks for your patience! I see this PR is failing test thanks |
This commit fixes a bug where zero values in SVG path definitions were incorrectly ignored when followed by whitespace and a decimal number. For example, "0 0 0 .25" was being parsed as "0" "0" "0.25" instead of the correct "0" "0" "0" "0.25". The root cause was that the scanner's charactersToBeSkipped included all whitespace, causing "0 .25" to be recognized as a single number "0.25". Changes: - Limited scanner.charactersToBeSkipped to only newlines (not all whitespace) - Added explicit whitespace handling in the operand parsing loop - This ensures zero values are correctly recognized as discrete operands The fix ensures that the testPathValuesWithLeadingZeros test passes, which verifies that shortcut SVG notations like "M 00.01 a 2 1 0 006 0" parse correctly to match their expanded equivalents.
This commit fixes a bug where zero values in SVG path definitions were incorrectly ignored when followed by whitespace and a decimal number. For example, "0 0 0 .25" was being parsed as "0" "0" "0.25" instead of the correct "0" "0" "0" "0.25". The root cause was that the scanner's automatic whitespace-skipping behavior caused the sequence "0 .25" to be recognized as a single number "0.25". Changes: - Temporarily disable charactersToBeSkipped when scanning for zeros - Manually skip separators to maintain precise control over parsing - Re-enable charactersToBeSkipped before calling scanFloat - This ensures zeros are correctly recognized as discrete operands while preserving normal scanning behavior for other numbers The fix ensures that the testPathValuesWithLeadingZeros test passes, which verifies that shortcut SVG notations like "M 00.01 a 2 1 0 006 0" parse correctly to match their expanded equivalents.
This commit fixes a bug where zero values in SVG path definitions were incorrectly ignored when followed by whitespace and a decimal number. For example, "0 0 0 .25" was being parsed as "0" "0" "0.25" instead of the correct "0" "0" "0" "0.25". The root cause was that the scanner's automatic whitespace-skipping behavior caused sequences like "0 .25" to be merged into "0.25", and consecutive zeros like "006" were being consumed by scanFloat as "6" instead of being parsed as "0", "0", "6". Changes: - Temporarily disable charactersToBeSkipped when scanning for zeros - Manually skip separators to maintain precise control over parsing - Add detected zeros as discrete operands - Skip scanFloat when zeros are added (continue loop to check for more zeros) - Only call scanFloat for non-zero numbers - This ensures zeros are correctly recognized as discrete operands The fix ensures that the testPathValuesWithLeadingZeros test passes, which verifies that shortcut SVG notations like "M 00.01 a 2 1 0 006 0" parse correctly to match their expanded equivalents.
|
this is now fixed in https://github.com/pocketsvg/PocketSVG/releases/tag/3.2.0 |
Issue
Any SVG string start with 0, has a whitespace after, and comes with dot, will make the zero being ignored.
For example, if there is a SVG string "0 0 0 .25", it will get "0" "0" "0.25", which we expect "0" "0" "0" "0.25"
Root cause
In
pathDefinitionParserwe setup the scanner to skip whitespace, which make this string "0 .25" to be recognised as "0.25"Fix
Test
Before
After
No error
