Skip to content

Commit

Permalink
[vector_graphics_compiler] fix-null-exception (flutter#8006)
Browse files Browse the repository at this point in the history
The following SVG throw an exception (when using flutter_svg) : https://sweden.a.bigcontent.io/v1/static/10000199.

This SVG contain an empty tag : <polygon xmlns="http://www.w3.org/2000/svg" fill="#0a287d" points="" id="polygon7"/> which lead to the issue.

This PR check if path is null to avoid the issue.

PR from dnfield/vector_graphics#254
  • Loading branch information
EArminjon authored Nov 8, 2024
1 parent 94d13ae commit dcbac07
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/vector_graphics_compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.15

* Fixes a bug where empty tags caused the parser to crash.

## 1.1.14

* Makes the package WASM compatible.
Expand Down
5 changes: 4 additions & 1 deletion packages/vector_graphics_compiler/lib/src/svg/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,10 @@ class SvgParser {
return false;
}
final ParentNode parent = _parentDrawables.last.drawable;
final Path path = pathFunc(this)!;
final Path? path = pathFunc(this);
if (path == null) {
return false;
}
final PathNode drawable = PathNode(path, _currentAttributes);
checkForIri(drawable);

Expand Down
2 changes: 1 addition & 1 deletion packages/vector_graphics_compiler/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: vector_graphics_compiler
description: A compiler to convert SVGs to the binary format used by `package:vector_graphics`.
repository: https://github.com/flutter/packages/tree/main/packages/vector_graphics_compiler
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+vector_graphics%22
version: 1.1.14
version: 1.1.15

executables:
vector_graphics_compiler:
Expand Down
14 changes: 14 additions & 0 deletions packages/vector_graphics_compiler/test/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:vector_graphics_compiler/src/svg/numbers.dart';
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart';

import 'test_svg_strings.dart';

void main() {
Expand Down Expand Up @@ -1948,6 +1949,19 @@ void main() {
],
);
});

test('Parse empty tag', () {
const String svgStr = '''
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
<polygon
fill="#0a287d"
points=""
id="triangle"/>
</svg>
''';

expect(parseWithoutOptimizers(svgStr), isA<VectorInstructions>());
});
}

const List<Paint> ghostScriptTigerPaints = <Paint>[
Expand Down

0 comments on commit dcbac07

Please sign in to comment.