Skip to content

Commit 84339e9

Browse files
committed
Fix zero value parsing in SVG paths (resolves #228)
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.
1 parent 53088f7 commit 84339e9

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Sources/SVGEngine.mm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ CGPathRef CGPathFromSVGPathString(NSString *svgString) {
547547
dispatch_once(&onceToken, ^{
548548
commands = [NSCharacterSet characterSetWithCharactersInString:kValidSVGCommands];
549549
separators = [NSMutableCharacterSet characterSetWithCharactersInString:@","];
550-
[(NSMutableCharacterSet *)separators formUnionWithCharacterSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
550+
[(NSMutableCharacterSet *)separators formUnionWithCharacterSet:NSCharacterSet.newlineCharacterSet];
551551
});
552552
scanner.charactersToBeSkipped = separators;
553553

@@ -558,6 +558,9 @@ CGPathRef CGPathFromSVGPathString(NSString *svgString) {
558558
scanner.scanLocation -= [cmdBuf length]-1;
559559
} else {
560560
while (!scanner.isAtEnd) {
561+
// Explicitly skip whitespace
562+
while ([scanner scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:NULL]) { }
563+
561564
NSUInteger zeros = 0;
562565
while ([scanner scanString:@"0" intoString:NULL]) { ++zeros; }
563566
// Start of a 0.x ?

0 commit comments

Comments
 (0)