Skip to content

Commit

Permalink
Avoid stack overflow when self-referential elemetns present, only use… (
Browse files Browse the repository at this point in the history
#218)

* Avoid stack overflow when self-referential elemetns present, only use first ID

* bumps
dnfield authored Oct 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c948a41 commit 6106ede
Showing 8 changed files with 64 additions and 12 deletions.
7 changes: 7 additions & 0 deletions packages/vector_graphics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 1.1.9

- Fix handling of invalid XML `@id` attributes.
- Fix handling of self-referential `<use/>` elements.
- Add `--out-dir` option to compiler.
- Tweak warning message for unhandled eleemnts.

## 1.1.8

- Fix bugs in transform parsing.
6 changes: 3 additions & 3 deletions packages/vector_graphics/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: vector_graphics
description: A vector graphics rendering package for Flutter.
version: 1.1.8
version: 1.1.9
homepage: https://github.com/dnfield/vector_graphics

environment:
@@ -10,13 +10,13 @@ environment:
dependencies:
flutter:
sdk: flutter
vector_graphics_codec: 1.1.8
vector_graphics_codec: 1.1.9

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
vector_graphics_compiler: 1.1.8
vector_graphics_compiler: 1.1.9

# Comment out before publishing
dependency_overrides:
7 changes: 7 additions & 0 deletions packages/vector_graphics_codec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 1.1.9

- Fix handling of invalid XML `@id` attributes.
- Fix handling of self-referential `<use/>` elements.
- Add `--out-dir` option to compiler.
- Tweak warning message for unhandled eleemnts.

## 1.1.8

- Fix bugs in transform parsing.
2 changes: 1 addition & 1 deletion packages/vector_graphics_codec/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: vector_graphics_codec
description: An encoding library for `package:vector_graphics`
version: 1.1.8
version: 1.1.9
homepage: https://github.com/dnfield/vector_graphics

environment:
7 changes: 7 additions & 0 deletions packages/vector_graphics_compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 1.1.9

- Fix handling of invalid XML `@id` attributes.
- Fix handling of self-referential `<use/>` elements.
- Add `--out-dir` option to compiler.
- Tweak warning message for unhandled eleemnts.

## 1.1.8

- Fix bugs in transform parsing.
16 changes: 11 additions & 5 deletions packages/vector_graphics_compiler/lib/src/svg/parser.dart
Original file line number Diff line number Diff line change
@@ -226,7 +226,9 @@ class _Elements {
maskResolver: parserState._definitions.getDrawable,
patternResolver: parserState._definitions.getDrawable,
);
parserState.checkForIri(group);
if ('#${parserState._currentAttributes.id}' != xlinkHref) {
parserState.checkForIri(group);
}
parent!.addChild(
group,
clipId: parserState._currentAttributes.clipPathId,
@@ -864,10 +866,11 @@ class SvgParser {
}

/// Whether this [DrawableStyleable] belongs in the [DrawableDefinitions] or not.
bool checkForIri(AttributedNode? drawable) {
bool checkForIri(AttributedNode drawable) {
assert('#${_currentAttributes.id}' != _currentAttributes.href);
final String iri = buildUrlIri();
if (iri != emptyUrlIri) {
_definitions.addDrawable(iri, drawable!);
_definitions.addDrawable(iri, drawable);
return true;
}
return false;
@@ -1797,6 +1800,9 @@ class _Resolver {
String? href,
) {
assert(!_sealed);
if (_shaders.containsKey(gradient.id)) {
return;
}
_shaders[gradient.id] = gradient;
if (href != null) {
href = 'url($href)';
@@ -1820,13 +1826,13 @@ class _Resolver {
/// Add the clip defined by [pathNodes] to the resolver identifier by [ref].
void addClipPath(String ref, List<Node> pathNodes) {
assert(!_sealed);
_clips[ref] = pathNodes;
_clips.putIfAbsent(ref, () => pathNodes);
}

/// Add the [drawable] to the resolver identifier by [ref].
void addDrawable(String ref, AttributedNode drawable) {
assert(!_sealed);
_drawables[ref] = drawable;
_drawables.putIfAbsent(ref, () => drawable);
}
}

6 changes: 3 additions & 3 deletions packages/vector_graphics_compiler/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: vector_graphics_compiler
description: A compiler for `package:vector_graphics`.
version: 1.1.8
version: 1.1.9
homepage: https://github.com/dnfield/vector_graphics

executables:
@@ -14,7 +14,7 @@ dependencies:
meta: ^1.7.0
path_parsing: ^1.0.1
xml: ^6.3.0
vector_graphics_codec: 1.1.8
vector_graphics_codec: 1.1.9
path: ^1.8.0

dev_dependencies:
@@ -25,7 +25,7 @@ dev_dependencies:
sdk: flutter
flutter_test:
sdk: flutter
vector_graphics: 1.1.8
vector_graphics: 1.1.9

# Comment out before publishing
dependency_overrides:
25 changes: 25 additions & 0 deletions packages/vector_graphics_compiler/test/parser_test.dart
Original file line number Diff line number Diff line change
@@ -4,6 +4,31 @@ import 'package:vector_graphics_compiler/vector_graphics_compiler.dart';
import 'test_svg_strings.dart';

void main() {
test('Reuse ID self-referentially', () {
final VectorInstructions instructions = parseWithoutOptimizers('''
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<rect x="2" y="2" width="20" height="20" id="path-1"/>
</defs>
<use id="path-1" fill="#FFFFFF" xlink:href="#path-1"/>
</svg>
''');

expect(instructions.paths.length, 1);
});

test('Self-referentially ID', () {
final VectorInstructions instructions = parseWithoutOptimizers('''
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<use id="path-1" fill="#FFFFFF" xlink:href="#path-1"/>
</svg>
''');

expect(instructions.paths.length, 0);
});

test('Text transform but no xy', () {
final VectorInstructions instructions = parseWithoutOptimizers('''
<svg viewBox="0 0 450 150" xmlns="http://www.w3.org/2000/svg">

0 comments on commit 6106ede

Please sign in to comment.