Fix the issue that zero has been ignored#228
Closed
kidd0717 wants to merge 1 commit intopocketsvg:masterfrom
Closed
Fix the issue that zero has been ignored#228kidd0717 wants to merge 1 commit intopocketsvg:masterfrom
kidd0717 wants to merge 1 commit intopocketsvg:masterfrom
Conversation
arielelkin
reviewed
Jul 1, 2025
| } | ||
| for (NSUInteger i = 0; i < zeros; ++i) { _operands.push_back(0.0); } | ||
|
|
||
| while ([scanner scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:NULL]) { } |
Collaborator
There was a problem hiding this comment.
why is there an empty while loop here? isn't this an infinite loop
Author
There was a problem hiding this comment.
It's not an infinite loop. It will move the scanner to next char if the current char is a whitespace.
arthurpazpicpay
approved these changes
Sep 30, 2025
Collaborator
|
@arthurpazpicpay @kidd0717 thanks for your patience! I see this PR is failing test thanks |
arielelkin
pushed a commit
that referenced
this pull request
Nov 11, 2025
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.
arielelkin
pushed a commit
that referenced
this pull request
Nov 11, 2025
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.
arielelkin
pushed a commit
that referenced
this pull request
Nov 11, 2025
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.
Collaborator
|
this is now fixed in https://github.com/pocketsvg/PocketSVG/releases/tag/3.2.0 |
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.
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
