Repository navigation
SVG: read rgb() with channels that are not integers - #2207
Merged
andersonhc merged 5 commits intoNov 18, 2026
Merged
Conversation
andersonhc
requested changes
Nov 15, 2026
andersonhc
left a comment
Collaborator
There was a problem hiding this comment.
One small thing: rebuilding the color from channels[:3] also lets malformed inputs through. For example, rgb(0,127.5,0,51,99) now succeeds and silently drops the extra values, while a missing closing parenthesis is accepted too.
Could you validate the parentheses and require three or four channels before rebuilding the string?
Author
|
Thanks, fixed. Before rebuilding the color, the value now has to be rgb(...) or rgba(...) with one pair of parentheses and 3 or 4 values, otherwise it raises ValueError. So rgb(0,127.5,0,51,99), a missing ")" and an extra ")" are rejected now. Integer values still go through color_from_rgb_string() as before. Added the 3 cases to the tests. |
# Conflicts: # CHANGELOG.md
andersonhc
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mermaid computes its theme colors and writes them as
fill:rgb(45,179.9999999999,184.5)in its stylesheets, as in the LegalQA diagrams. Anrgb()with commas and a channel that isn't an integer fails withValueError: invalid literal for int() with base 10. These rules aren't applied today, but they would be once descendant selectors are (#2201).Such a color is now read as in CSS Color 4, like the space-separated syntax already is. Integers and percentages still go through fpdf2's own parser, and an integer 4th value still sets an alpha from 0 to 255. The comma handling moved into
_comma_rgb_color()to keepsvgcolor()readable.Two new cases in
parameters.pycoverrgb(0, 127.5, 1e2)andrgb(255, 127.5, 0, 51); both fail without the change.