]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix off-by-one error in 'css--hex-to-rgb'
authorSimen Heggestøyl <simenheg@gmail.com>
Sun, 28 Jan 2018 12:03:05 +0000 (13:03 +0100)
committerSimen Heggestøyl <simenheg@gmail.com>
Sun, 28 Jan 2018 12:28:28 +0000 (13:28 +0100)
* 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
test/lisp/textmodes/css-mode-tests.el

index 6bd08f5919061e5df2616c808dbdf606760ffb03..135c0d5f92825bd987b15c3aac5b10ab301da066 100644 (file)
@@ -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))
index 272d281217ef4b2bb7bd29cd1bd72c3a1da350cf..4883123843d99f3d95ca22a1ce2a9798f7d5c170 100644 (file)
                   ("#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))