Repository navigation
[vector_graphics_compiler] Handle coordinate lists on text and tspan - #13287
Conversation
There was a problem hiding this comment.
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.
| // 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; | ||
|
|
There was a problem hiding this comment.
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 }\nThere was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
I think it's better to throw an exception to say lists aren't implemented instead of just throwing away the other values
|
That makes sense, thanks! It now throws an |
…gc-text-coordinate-list
|
@walley892 can you be a secondary reviewer here please |
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
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
SVG allows
x,y,dxanddyontextandtspanto be a list, one value per character. The compiler parsed them as a single number, so a list likex="0 4.86 10.01"threw a confusingFormatException: Invalid double.Lists aren't supported, so it now throws an
UnimplementedErrorthat names the attribute and value. Single values work as before.Fixes flutter/flutter#165490
Pre-Review Checklist
[shared_preferences]///).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-assistbot 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
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