Skip to content

[vector_graphics_compiler] Handle coordinate lists on text and tspan - #13287

Merged
auto-submit[bot] merged 5 commits into
flutter:mainfrom
mackings:vgc-text-coordinate-list
Oct 27, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:mainfrom
mackings:vgc-text-coordinate-list

Conversation

@mackings

@mackings mackings commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

SVG allows x, y, dx and dy on text and tspan to be a list, one value per character. The compiler parsed them as a single number, so a list like x="0 4.86 10.01" threw a confusing FormatException: Invalid double.

Lists aren't supported, so it now throws an UnimplementedError that names the attribute and value. Single values work as before.

Fixes flutter/flutter#165490

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

@github-actions github-actions Bot added p: vector_graphics triage-engine Should be looked at in engine triage labels Oct 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the SVG parser in vector_graphics_compiler to extract and use only the first coordinate when text or tspan elements contain a list of coordinates, preventing potential crashes. A review comment suggests optimizing the _firstListValue helper by caching the RegExp instance and using indexOf and substring instead of split to avoid unnecessary string allocations.

Comment on lines +1573 to +1576
// Text and tspan can list one coordinate per character. Per-character
// positioning isn't supported, so only the first coordinate is used.
String? _firstListValue(String? raw) => raw?.trim().split(RegExp(r'[\s,]+')).first;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using split on the entire coordinate string is inefficient because it allocates a list of all substrings, which can be quite large for long coordinate lists (e.g., one coordinate per character in a long text block). Additionally, creating a new RegExp instance on every call of _firstListValue adds unnecessary overhead.\n\nInstead, we can reuse a single static RegExp instance and use indexOf and substring to efficiently extract only the first coordinate without splitting the rest of the string. This also safely handles empty or whitespace-only strings by returning null.

  static final RegExp _coordinateSeparator = RegExp(r'[\\s,]');\n\n  // Text and tspan can list one coordinate per character. Per-character\n  // positioning isn't supported, so only the first coordinate is used.\n  String? _firstListValue(String? raw) {\n    if (raw == null) {\n      return null;\n    }\n    final String trimmed = raw.trim();\n    if (trimmed.isEmpty) {\n      return null;\n    }\n    final int index = trimmed.indexOf(_coordinateSeparator);\n    return index == -1 ? trimmed : trimmed.substring(0, index);\n  }\n

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, thank you! x/y are parsed for every element, so I moved the RegExp to a static field and switched to indexOf/substring. The suggested snippet came through escaped (r'[\\s,]' would match a backslash), so I used r'[\s,]' instead.

@gaaclarke gaaclarke added the CICD Run CI/CD label Oct 19, 2026
@gaaclarke
gaaclarke self-requested a review October 19, 2026 20:02

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's better to throw an exception to say lists aren't implemented instead of just throwing away the other values

@mackings

Copy link
Copy Markdown
Contributor Author

That makes sense, thanks! It now throws an UnimplementedError that names the attribute, e.g. A list of values for "x" is not supported: "0 4.86 10.01".

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 20, 2026
@mackings
mackings requested a review from gaaclarke October 20, 2026 07:31

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, thanks

@gaaclarke gaaclarke added the CICD Run CI/CD label Oct 20, 2026
@gaaclarke
gaaclarke requested a review from walley892 October 20, 2026 15:55
@gaaclarke

Copy link
Copy Markdown
Member

@walley892 can you be a secondary reviewer here please

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 26, 2026
@auto-submit
auto-submit Bot merged commit e71b3fd into flutter:main Oct 27, 2026
14 checks passed
GhagSagar23 pushed a commit to Kryonex-Labs/flutter that referenced this pull request Oct 27, 2026
flutter/packages@23a05b6...a8549ae

2026-10-27 [email protected] [material_ui]
Deprecate the black/white parameters in `Typography.material2021`
(flutter/packages#13443)
2026-10-27 [email protected] [shared_preferences] Defer
SharedPreferences fetch in `LegacySharedPreferencesPlugin` until first
use on Android (flutter/packages#13431)
2026-10-27 [email protected] [material_ui] Fix MenuAnchor
non-Unicode shortcut labels on JS web (flutter/packages#13370)
2026-10-27 [email protected] [material_ui]
Add Checkbox.markInsets (flutter/packages#12690)
2026-10-27 [email protected]
[vector_graphics_compiler] Handle coordinate lists on text and tspan
(flutter/packages#13287)
2026-10-27 [email protected]
[cupertino_ui] Unskip web tests that pass on CanvasKit and Skwasm:
nav_bar_transition_test, refresh_test, route_test,
text_field_cursor_test (flutter/packages#13439)
2026-10-27 [email protected] [material_ui] Fix
`TextTheme` and `Typography` `debugFillProperties` defaults
(flutter/packages#13374)
2026-10-27 [email protected] [material_ui]
Update out-of-date typography documentation (flutter/packages#13372)
2026-10-27 [email protected] [shared_preferences_foundation] Fix web
compilation of apps that import the package (flutter/packages#13447)
2026-10-26 [email protected] Fix AI guidelines link in PR template
(flutter/packages#13411)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
flutter/packages@23a05b6...a8549ae

2026-10-27 [email protected] [material_ui]
Deprecate the black/white parameters in `Typography.material2021`
(flutter/packages#13443)
2026-10-27 [email protected] [shared_preferences] Defer
SharedPreferences fetch in `LegacySharedPreferencesPlugin` until first
use on Android (flutter/packages#13431)
2026-10-27 [email protected] [material_ui] Fix MenuAnchor
non-Unicode shortcut labels on JS web (flutter/packages#13370)
2026-10-27 [email protected] [material_ui]
Add Checkbox.markInsets (flutter/packages#12690)
2026-10-27 [email protected]
[vector_graphics_compiler] Handle coordinate lists on text and tspan
(flutter/packages#13287)
2026-10-27 [email protected]
[cupertino_ui] Unskip web tests that pass on CanvasKit and Skwasm:
nav_bar_transition_test, refresh_test, route_test,
text_field_cursor_test (flutter/packages#13439)
2026-10-27 [email protected] [material_ui] Fix
`TextTheme` and `Typography` `debugFillProperties` defaults
(flutter/packages#13374)
2026-10-27 [email protected] [material_ui]
Update out-of-date typography documentation (flutter/packages#13372)
2026-10-27 [email protected] [shared_preferences_foundation] Fix web
compilation of apps that import the package (flutter/packages#13447)
2026-10-26 [email protected] Fix AI guidelines link in PR template
(flutter/packages#13411)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: vector_graphics triage-engine Should be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_svg] FormatException: Invalid double when x or y values contain a List<double>

3 participants