`color-values-from-color-spec` (new in Emacs 28) erroneously accepted
leading whitespace and hex floats in rgbi: components.
Reported by Philip Kaludercic.
* src/xfaces.c (parse_float_color_comp): Disallow leading whitespace
and hex floats.
* test/src/xfaces-tests.el
(xfaces-internal-color-values-from-color-spec): Add test cases.
static double
parse_float_color_comp (const char *s, const char *e)
{
+ /* Only allow decimal float literals without whitespace. */
+ for (const char *p = s; p < e; p++)
+ if (!((*p >= '0' && *p <= '9')
+ || *p == '.' || *p == '+' || *p == '-' || *p == 'e' || *p == 'E'))
+ return -1;
char *end;
double x = strtod (s, &end);
return (end == e && x >= 0 && x <= 1) ? x : -1;
'(0 32768 6554)))
(should (equal (color-values-from-color-spec "rgbi:1e-3/1.0e-2/1e0")
'(66 655 65535)))
- (should (equal (color-values-from-color-spec "rgbi:0/0.5/10") nil)))
+ (should (equal (color-values-from-color-spec "rgbi:0/0.5/10") nil))
+ (should (equal (color-values-from-color-spec "rgbi:0/0/ 0") nil))
+ (should (equal (color-values-from-color-spec "rgbi:0/0x0/0") nil))
+ (should (equal (color-values-from-color-spec "rgbi:0/+0x1/0") nil)))
(provide 'xfaces-tests)