Skip to content

Conversation

@kidd0717
Copy link

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 pathDefinitionParser we setup the scanner to skip whitespace, which make this string "0 .25" to be recognised as "0.25"

Fix

  • Update skip characters to only newline
  • Ignore whitespace in the parser

Test

Before

Screenshot 2025-05-15 at 17 57 07

Simulator Screenshot - iPhone 16 Pro - 2025-05-15 at 17 54 58

After

No error
Simulator Screenshot - iPhone 16 Pro - 2025-05-15 at 17 52 49

}
for (NSUInteger i = 0; i < zeros; ++i) { _operands.push_back(0.0); }

while ([scanner scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:NULL]) { }
Copy link
Collaborator

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

Copy link
Author

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.

@kidd0717 kidd0717 closed this Oct 1, 2025
@kidd0717 kidd0717 reopened this Oct 1, 2025
@arielelkin
Copy link
Collaborator

@arthurpazpicpay @kidd0717 thanks for your patience! I see this PR is failing test testPathValuesWithLeadingZeros, could you please update it and I'll review it?

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.
@arielelkin
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants