Skip to content

Validate unsupported and malformed color values - #147

Open
OskarEichler wants to merge 1 commit into
ku1ik:masterfrom
OskarEichler:codex/rainbow-color-validation
Open

Validate unsupported and malformed color values#147
OskarEichler wants to merge 1 commit into
ku1ik:masterfrom
OskarEichler:codex/rainbow-color-validation

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Reject unsupported color definitions and require RGB arrays to contain exactly three components instead of returning nil, raising incidental NoMethodError, or silently discarding extras.

Reproduction

On current master, Rainbow('x').color(nil) returns through a nil color and fails later with NoMethodError; color([]) and two-element arrays also raise incidental errors; [1, 2, 3, 4] silently ignores the fourth component. The documented contract accepts one color definition or exactly three RGB values.

The symbol branch is extracted into a private class helper solely to keep the expanded validation within the repository's lint thresholds.

Verification

  • Existing suite: 220 examples, 0 failures on Ruby 3.2.11 and 4.0.6.
  • RuboCop: 15 files, 0 offenses on both Rubies.
  • External model: 2,037 checks per Ruby, including unsupported types, 0/1/2/4 component arrays, range failures, and all 1,000 combinations of valid Integer, Float, Rational and BigDecimal components on both foreground/background paths.
  • Focused 20,000-call microbenchmark showed unchanged allocations; RGB median was 21.39 ms vs 20.21 ms on Ruby 4.0 and 21.62 ms vs 21.55 ms on Ruby 3.2. This is a microbenchmark, not application throughput.
  • Rebuilt gem: 14 expected files and successful packaged loads on both Rubies.
  • No test files changed.

Breaking change

Undocumented invalid definitions now consistently raise ArgumentError; surplus RGB components are no longer ignored. Valid documented definitions are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant