Skip to content

Make frontend CSS color validation Chromium-only (remove DOM style fallback)#2946

Merged
sawka merged 6 commits intomainfrom
copilot/add-color-validator-file
Feb 27, 2026
Merged

Make frontend CSS color validation Chromium-only (remove DOM style fallback)#2946
sawka merged 6 commits intomainfrom
copilot/add-color-validator-file

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

The new color validator is used exclusively in the Electron/Chromium frontend, so fallback parsing via temporary DOM elements is unnecessary. This update tightens the implementation to rely on the browser-native CSS capability check only.

  • Scope

    • Keep validateCssColor(color: string): string behavior unchanged (returns normalized type for valid colors, throws on invalid).
    • Remove non-Chromium fallback logic from validation path.
  • Implementation

    • frontend/util/color-validator.ts
      • isValidCssColor now exclusively uses:
        • CSS.supports("color", color)
      • Removed fallback using document.createElement(...).style.color assignment/parsing.
  • Behavioral contract (unchanged)

    • Valid values still return specific type strings (hex, hex8, rgb, rgba, hsl, keyword, etc.).
    • Invalid values still throw Error("Invalid CSS color: ...").
function isValidCssColor(color: string): boolean {
    if (typeof CSS == "undefined" || typeof CSS.supports != "function") {
        return false;
    }
    return CSS.supports("color", color);
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 27, 2026

Deploying waveterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: e3a3c73
Status:⚡️  Build in progress...

View logs

Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title [WIP] Add color validator function for CSS colors Add frontend CSS color validator utility with typed classification and strict invalid-color errors Feb 27, 2026
@sawka sawka marked this pull request as ready for review February 27, 2026 01:33
const temp = document.createElement("div");
temp.style.color = "";
temp.style.color = color;
return temp.style.color != "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Use strict equality operator

Should use !== instead of != when comparing to empty string. The project uses != only for null/undefined checks, not for string comparisons.

Suggested change
return temp.style.color != "";
return temp.style.color !== "";

throw new Error(`Invalid CSS color: ${String(color)}`);
}
const normalizedColor = color.trim();
if (normalizedColor == "" || !isValidCssColor(normalizedColor)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Use strict equality operator

Should use === instead of == when comparing to empty string. The project uses == only for null/undefined checks, not for string comparisons.

Suggested change
if (normalizedColor == "" || !isValidCssColor(normalizedColor)) {
if (normalizedColor === "" || !isValidCssColor(normalizedColor)) {

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Feb 27, 2026

Code Review Summary

Status: No New Issues Found | Recommendation: Address existing comments before merge

Note

All issues in this PR have already been identified in previous comments (strict equality operators on lines 9 and 46 of color-validator.ts). No additional issues found.

Files Reviewed (3 files)
  • Taskfile.yml - Copyright year update, no issues
  • frontend/util/color-validator.ts - Issues already commented
  • frontend/util/color-validator.test.ts - No issues

Fix these issues in Kilo Cloud

Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title Add frontend CSS color validator utility with typed classification and strict invalid-color errors Make frontend CSS color validation Chromium-only (remove DOM style fallback) Feb 27, 2026
const NamedColorRegex = /^[a-z]+$/i;

function isValidCssColor(color: string): boolean {
if (typeof CSS == "undefined" || typeof CSS.supports != "function") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Use strict equality operators

Use === instead of == and !== instead of != for type-safe comparisons.

Suggested change
if (typeof CSS == "undefined" || typeof CSS.supports != "function") {
if (typeof CSS === "undefined" || typeof CSS.supports !== "function") {

}

export function validateCssColor(color: string): string {
if (typeof color != "string") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Use strict equality operator

Use !== instead of != for type-safe comparison.

Suggested change
if (typeof color != "string") {
if (typeof color !== "string") {

@sawka sawka merged commit 9c3cf98 into main Feb 27, 2026
5 of 6 checks passed
@sawka sawka deleted the copilot/add-color-validator-file branch February 27, 2026 23:48
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.

2 participants