From 97defdfc36d9a83a3081c5f76e249f908645f7ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Simen=20Heggest=C3=B8yl?= Date: Sun, 28 Jan 2018 13:03:05 +0100 Subject: [PATCH] Fix off-by-one error in 'css--hex-to-rgb' * lisp/textmodes/css-mode.el (css--hex-to-rgb): Fix off-by-one error. * test/lisp/textmodes/css-mode-tests.el (css-test-hex-to-rgb): Add regression tests for the above fix. --- lisp/textmodes/css-mode.el | 2 +- test/lisp/textmodes/css-mode-tests.el | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 6bd08f59190..135c0d5f928 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1458,7 +1458,7 @@ should not be mixed with those in color.el." (if-let* ((alpha (css--hex-alpha hex)) (a (css--format-rgba-alpha (/ (string-to-number alpha 16) - (float (expt 16 (length alpha))))))) + (float (- (expt 16 (length alpha)) 1)))))) (format "rgba(%d, %d, %d, %s)" r g b a) (format "rgb(%d, %d, %d)" r g b)) t)) diff --git a/test/lisp/textmodes/css-mode-tests.el b/test/lisp/textmodes/css-mode-tests.el index 272d281217e..4883123843d 100644 --- a/test/lisp/textmodes/css-mode-tests.el +++ b/test/lisp/textmodes/css-mode-tests.el @@ -281,7 +281,9 @@ ("#fff" "rgb(255, 255, 255)") ("#ffffff" "rgb(255, 255, 255)") ("#ffffff80" "rgba(255, 255, 255, 0.5)") - ("#fff8" "rgba(255, 255, 255, 0.5)"))) + ("#fff0" "rgba(255, 255, 255, 0)") + ("#fff8" "rgba(255, 255, 255, 0.53)") + ("#ffff" "rgba(255, 255, 255, 1)"))) (with-temp-buffer (css-mode) (insert (nth 0 item)) -- 2.39.5