emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 97defdf: Fix off-by-one error in 'css--hex-to-rgb'


From: Simen Heggestøyl
Subject: [Emacs-diffs] master 97defdf: Fix off-by-one error in 'css--hex-to-rgb'
Date: Sun, 28 Jan 2018 07:28:57 -0500 (EST)

branch: master
commit 97defdfc36d9a83a3081c5f76e249f908645f7ec
Author: Simen Heggestøyl <address@hidden>
Commit: Simen Heggestøyl <address@hidden>

    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 6bd08f5..135c0d5 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 272d281..4883123 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]