-
Notifications
You must be signed in to change notification settings - Fork 601
validate gradient color stops #2492
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
Conversation
alixander
left a comment
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.
I think the check is more precise/expected in ValidColor. Like it's got a gradient pattern, but it's just not valid.
|
Hey @alixander , there's another way to solve this problem i.e. by validating colors during rendering instead of at compile time.
Approach 2 Closed PR(#2491):
I went with the first approach since it fails faster and keeps changes contained, but I’d love your thoughts on which one you prefer. |
|
I meant if you just add your current check to here: https://github.com/terrastruct/d2/blob/master/lib/color/color.go#L514 , it's cleaner |
Ah okay, that makes sense. |
alixander
left a comment
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.
lgtm!
Currently, D2 does not validate gradient color stops, it just renders black color in case the gradient colors are invalid.
This PR adds the functionality to validate each color stop & in case it's invalid, it throws an error.
As per D2 website
fill&strokesupports css color names & hex colors apart from gradients, however inside gradient D2 supports all color formats (e.g rgb, hsl, etc), hence I usedcsscolorparserlibrary instead of checking againstNamedColors&ColorHexRegex.filldocs: https://d2lang.com/tour/style#fill/fixes #2490