config: improve validation of color values, default alpha to 0xff

Reject color values that aren't in either RGB, or ARGB format. That
is, color values that aren't hexadecimal numbers with either 6 or 8
digits.

Also, if a color value is allowed to have an alpha component, and the
user left it out, default to 0xff (opaque) rather than 0x00 (fully
transparent).

Closes #1526
This commit is contained in:
Daniel Eklöf 2023-10-26 16:22:41 +02:00
parent 85a4e4ccc1
commit 02fff24b4f
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 34 additions and 6 deletions

View file

@ -426,6 +426,10 @@ test_color(struct context *ctx, bool (*parse_fun)(struct context *ctx),
{"ffffff", 0xffffff},
{"ffffffff", 0xffffffff, !alpha_allowed},
{"aabbccdd", 0xaabbccdd, !alpha_allowed},
{"00", 0, true},
{"0000", 0, true},
{"00000", 0, true},
{"000000000", 0, true},
{"unittest-invalid-color", 0, true},
};