-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[vector_graphics_compiler] Fix rgb/rgba color parsing to support modern CSS syntax #10538
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
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 refactors the color parsing logic for rgb() and rgba() to support modern CSS syntax, including space-separated values, percentage-based values, and the slash separator for the alpha channel. The implementation is consolidated, and the old rgb parsing logic is removed. Comprehensive tests have been added to cover the new parsing capabilities.
The changes are well-structured and the added tests are thorough. I have one suggestion to improve the strictness of the parsing to better align with CSS standards.
Thanks for the contribution! Once you've completed the checklist, please mark the PR as ready for review.
Please make sure to follow the linked style guide. |
057153b to
16bf81a
Compare
|
@stuartmorgan-g Completed the checklist. This is my first PR to any flutter/dart repo. If anything is not exactly correct, please let me know and I'll address. |
|
Ping @stuartmorgan-g . Any chance we can get this fix reviewed/merged? |
|
I can do an initial review, but this will need a review from the engine team. Review capacity tends to be low in December, which is probably why this hasn't been picked up yet. |
…rn CSS syntax - Consolidate rgb() and rgba() parsing into single implementation - Add support for space-separated color values - Add support for percentage-based RGB values - Add support for slash (/) separator before alpha channel - Handle both comma and space delimiters - Add comprehensive test coverage for various color formats
- Add parseRgbFunction in colors.dart with character-by-character state machine parser for stricter CSS compliance - Support modern (space-separated with slash) and legacy (comma-separated) syntax variations - Clamp out-of-bounds values instead of throwing - Add comprehensive tests for valid syntax, out-of-bounds values, and invalid syntax detection
a7f24a0 to
efeb1a7
Compare
Replace character-by-character state machine with cleaner split-based approach using standard string operations (split, trim, where).
|
Thank you for the review @stuartmorgan-g . I completely re-wrote to a fresh implementation that checks strictly for the format and handles correctly all the cases (including weird ones such as I also added tests for a lot of invalid cases. Bonus: I also added handling for
|
|
/gemini review |
There was a problem hiding this comment.
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 refactors the CSS color parsing for rgb() and rgba() to support modern syntax, including space-separated values, percentage values, and the slash separator for the alpha channel. The implementation is consolidated into a new parseRgbFunction, and the old parsing logic is removed. Comprehensive tests are added to cover various valid and invalid color formats.
I've found one minor bug in the new parsing logic for mixed comma and space-separated values, and I've left a comment with a suggested fix. Otherwise, the changes look good and the test coverage is excellent.
…B parsing Handle multiple spaces in first value of comma-separated syntax by filtering empty strings after split.
This PR solves flutter/flutter#179261
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).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 ↩3