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'.
This commit is contained in:
Simen Heggestøyl 2017-12-16 09:37:11 +01:00
parent 804b37ca63
commit 63b6281fdd
2 changed files with 7 additions and 1 deletions

View file

@ -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)))

View file

@ -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