emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs-26 63b6281: Fix off-by-one error in 'css--hex-color'


From: Simen Heggestøyl
Subject: [Emacs-diffs] emacs-26 63b6281: Fix off-by-one error in 'css--hex-color'
Date: Sat, 16 Dec 2017 03:47:32 -0500 (EST)

branch: emacs-26
commit 63b6281fdd9c00c6d968e936289c1e32aa9d0dd3
Author: Simen Heggestøyl <address@hidden>
Commit: Simen Heggestøyl <address@hidden>

    Fix off-by-one error in 'css--hex-color'
    
    * lisp/textmodes/css-mode.el (css--hex-color): Fix off-by-one error.
    
    * test/lisp/textmodes/css-mode-tests.el (css-test-hex-color): New test
    for 'css--hex-color'.
---
 lisp/textmodes/css-mode.el            | 2 +-
 test/lisp/textmodes/css-mode-tests.el | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 1de4ff0..f2481da 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1037,7 +1037,7 @@ This recognizes CSS-color-4 extensions."
 STR is the incoming CSS hex color.
 This function simply drops any transparency."
   ;; Either #RGB or #RRGGBB, drop the "A" or "AA".
-  (if (> (length str) 4)
+  (if (> (length str) 5)
       (substring str 0 7)
     (substring str 0 4)))
 
diff --git a/test/lisp/textmodes/css-mode-tests.el 
b/test/lisp/textmodes/css-mode-tests.el
index 47cf5f9..1e58751 100644
--- a/test/lisp/textmodes/css-mode-tests.el
+++ b/test/lisp/textmodes/css-mode-tests.el
@@ -295,6 +295,12 @@
         (insert input ")"))
       (should (equal (css--hsl-color) "#ff0000")))))
 
+(ert-deftest css-test-hex-color ()
+  (should (equal (css--hex-color "#abc") "#abc"))
+  (should (equal (css--hex-color "#abcd") "#abc"))
+  (should (equal (css--hex-color "#aabbcc") "#aabbcc"))
+  (should (equal (css--hex-color "#aabbccdd") "#aabbcc")))
+
 (ert-deftest css-test-named-color ()
   (dolist (text '("@mixin black" "@include black"))
     (with-temp-buffer



reply via email to

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