mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-19 14:45:29 +00:00
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Go's min/max propagate NaN, so "nan" got past parse_opacity and failed later with an unclear json.Marshal error, while the Python parser silently clamped it to 0. Reject NaN in both, report a clear error message for invalid opacity values, and replace the regression test with a table test of parse_opacity covering clamping and invalid inputs.
17 lines
375 B
Go
17 lines
375 B
Go
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
|
|
|
|
package at
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"strconv"
|
|
)
|
|
|
|
func parse_opacity(arg string) (float64, error) {
|
|
ans, err := strconv.ParseFloat(arg, 64)
|
|
if err != nil || math.IsNaN(ans) {
|
|
return 0, fmt.Errorf("Invalid opacity %#v: must be a number between 0 and 1", arg)
|
|
}
|
|
return max(0, min(ans, 1)), nil
|
|
}
|