Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vector_graphics_compiler] fix: handle parsing stroke-width with an invalid value #8004

Merged
merged 20 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.13

* Fixes an issue when parse double with 'none' value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a period; see the PR checklist link for CHANGELOG style.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"when parsing a double with a value of 'none'."


## 1.1.12

* Transfers the package source from https://github.com/dnfield/vector_graphics
Expand Down
9 changes: 2 additions & 7 deletions packages/vector_graphics_compiler/lib/src/svg/numbers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import 'theme.dart';
/// which is stripped off when parsed to a `double`.
///
/// Passing `null` will return `null`.
double? parseDouble(String? rawDouble, {bool tryParse = false}) {
assert(tryParse != null); // ignore: unnecessary_null_comparison
double? parseDouble(String? rawDouble) {
if (rawDouble == null) {
return null;
}
Expand All @@ -26,10 +25,7 @@ double? parseDouble(String? rawDouble, {bool tryParse = false}) {
.replaceFirst('pt', '')
.trim();

if (tryParse) {
return double.tryParse(rawDouble);
}
return double.parse(rawDouble);
return double.tryParse(rawDouble);
}

/// Convert [degrees] to radians.
Expand Down Expand Up @@ -81,7 +77,6 @@ double? parseDoubleWithUnits(
}
final double? value = parseDouble(
rawDouble,
tryParse: tryParse,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tryParse parameter to parseDoubleWithUnits is now ignored; we should not have parameters that don't do anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will check it

);

return value != null ? value * unit : null;
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 @@ -5,7 +5,7 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+
# See https://github.com/flutter/flutter/issues/157626 before publishing a new
# version.
publish_to: none
version: 1.1.12
version: 1.1.13

executables:
vector_graphics_compiler:
Expand Down
4 changes: 4 additions & 0 deletions packages/vector_graphics_compiler/test/parsers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ void main() {
expect(parseDoubleWithUnits('1pt', theme: const SvgTheme()), 1 + 1 / 3);
});

test('"none" conversion', () {
expect(parseDoubleWithUnits('none', theme: const SvgTheme()), null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing the specific change to the parsing function, but isn't testing anything related to the original issue. It's not at all clear from the change and the test what actually happens now in the original case of the issue this PR is intended to fix. Does returning null instead of throwing work, or does it just create a different issue elsewhere in that codepath?

If the goal is to fix the case of an SVG with percentage values or none values, we should have a test that exercises that, and ensures that the higher-level behavior is as desired with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @stuartmorgan , what kind of test cases need to be added, do you have any suggestions?
currently I am also trying to read the documentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You provided an SVG that triggered this error in a comment above; a test that parsed a minimal version of that SVG and ensured that it behaved as expected seems like it would give good coverage of this use case.

});

test('Parse a transform with scientific notation', () {
expect(
parseTransform('translate(9e-6,6.5e-4)'),
Expand Down