Skip to content

Commit

Permalink
Avoid invalid dasharrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield committed Jan 11, 2022
1 parent c728d60 commit 65dbfc6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix bug with incorrect fills in some cases of `<use>` elements.
- Analysis cleanup of Dart code.
- Fix bug where self-closing `<g>` tags could alter rendering.
- Fix bug where an invalid `@stroke-dasharray` could cause an infinite loop.

## 1.0.0

Expand Down
3 changes: 3 additions & 0 deletions example/assets/simple/invalid_dash_array.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added golden/simple/invalid_dash_array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions lib/src/svg/xml_parsers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,18 @@ CircularIntervalList<double>? parseDashArray(
}

final List<String> parts = rawDashArray!.split(RegExp(r'[ ,]+'));
return CircularIntervalList<double>(parts
.map((String part) =>
parseDoubleWithUnits(part, fontSize: fontSize, xHeight: xHeight)!)
.toList());
final List<double> doubles = <double>[];
for (final String part in parts) {
final double dashOffset =
parseDoubleWithUnits(part, fontSize: fontSize, xHeight: xHeight)!;
if (dashOffset != 0) {
doubles.add(dashOffset);
}
}
if (doubles.isEmpty) {
return null;
}
return CircularIntervalList<double>(doubles);
}

/// Parses a @stroke-dashoffset into a [DashOffset].
Expand Down

0 comments on commit 65dbfc6

Please sign in to comment.