From c51dec791656d54d632b3b1d4049701983e892d3 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 24 Aug 2021 20:06:17 +0300 Subject: [PATCH] Fixed bug with converting short hex color to long --- badge.go | 4 +++- badge_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/badge.go b/badge.go index 1b3553e..3b353aa 100644 --- a/badge.go +++ b/badge.go @@ -220,7 +220,9 @@ func formatColor(c string) string { // Short hex if len(c) == 3 { - c = c + c + c = strings.Repeat(string(c[0]), 2) + + strings.Repeat(string(c[1]), 2) + + strings.Repeat(string(c[2]), 2) } return c diff --git a/badge_test.go b/badge_test.go index eb643be..b2f74f5 100644 --- a/badge_test.go +++ b/badge_test.go @@ -148,7 +148,7 @@ func (s *BadgeSuite) TestBlackAndWhite(c *C) { func (s *BadgeSuite) TestAux(c *C) { c.Assert(formatColor("000000"), Equals, "000000") c.Assert(formatColor("#000000"), Equals, "000000") - c.Assert(formatColor("#000"), Equals, "000000") + c.Assert(formatColor("#4c1"), Equals, "44cc11") c.Assert(calcLumColor(0.7), Equals, 0.4479884124418833) c.Assert(calcLumColor(0.01), Equals, 0.0007739938080495357)