Skip to content

Commit

Permalink
clamp instead of mod
Browse files Browse the repository at this point in the history
  • Loading branch information
zackradisic committed Sep 25, 2024
1 parent 5b5b680 commit 5f8872b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/css/values/color_js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ fn colorIntFromJS(globalThis: *JSC.JSGlobalObject, input: JSC.JSValue, comptime
return null;
}

return @mod(input.coerce(i32, globalThis), 256);
// CSS spec says to clamp values to their valid range so we'll respect that here
return std.math.clamp(input.coerce(i32, globalThis), 0, 255);
}

// https://github.com/tmux/tmux/blob/dae2868d1227b95fd076fb4a5efa6256c7245943/colour.c#L44-L55
Expand Down

0 comments on commit 5f8872b

Please sign in to comment.