From: Simen Heggestøyl Date: Sun, 28 Jan 2018 12:03:05 +0000 (+0100) Subject: Fix off-by-one error in 'css--hex-to-rgb' X-Git-Tag: emacs-27.0.90~5793 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=97defdfc36d9a83a3081c5f76e249f908645f7ec;p=emacs.git 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. --- 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))