fix(rgbgradient): raise a clear error for an empty color gradient - #289
Open
eeshsaxena wants to merge 1 commit into
Open
fix(rgbgradient): raise a clear error for an empty color gradient#289eeshsaxena wants to merge 1 commit into
eeshsaxena wants to merge 1 commit into
Conversation
`_handle_rgbgradient_dict()` accessed `gradient[-1]` in the smooth-gradient
step without first checking that any color was parsed. A dict with no
"colors" key (or `"colors": []`), which is reachable through the documented
Python API, therefore raised `IndexError: list index out of range` instead
of the intended `ValueError("no color: ...")` that `process_value()` raises
right after. rgbgradientv2 hits it too, since it reuses this function.
Guard the smooth-gradient step with `if gradient and ...`; the empty case
now falls through to the existing "no color" check in both handlers.
Adds regression tests to test_rgbgradient.py and test_rgbgradientv2.py.
Contributor
Author
|
Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix ( |
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.
Bug
_handle_rgbgradient_dict()(rivalcfg/handlers/rgbgradient.py) accessesgradient[-1]in its smooth-gradient step without checking that any color was parsed:A dict with no
"colors"key, or"colors": [], is reachable through the documented Python dict API, and it makesgradientempty.gradient[-1]then raisesIndexError: list index out of rangebeforeprocess_value()can reach its ownif len(gradient) == 0: raise ValueError("no color: ...")check just below.rgbgradientv2is affected too, since itsprocess_value()reuses this same function.Fix
Guard the smooth-gradient step with
if gradient and .... The empty case now falls through to the existing"no color"ValueErrorin bothrgbgradientandrgbgradientv2, which is the intended behavior. Valid single colors, gradients, and tuples are unaffected.Tests
Adds regression tests to
test/handlers/test_rgbgradient.pyandtest/handlers/test_rgbgradientv2.py(dict without acolorskey, and emptycolors). They fail onmaster(IndexError) and pass with this change; the full gradient handler suite stays green (86 passed).blackandflake8are clean.