diff options
author | Clar Fon <usr@ltdk.xyz> | 2022-02-07 16:21:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-07 21:21:02 +0000 |
commit | 9911b66aea076347cfb271b12c90bc31e4e5b5f8 (patch) | |
tree | 5f979a4f62479e6f78fdb8653bc18df9c77b7136 /models/issue_label.go | |
parent | 3a91f845e81aae386afb0210f3a66b88109e99a2 (diff) | |
download | gitea-9911b66aea076347cfb271b12c90bc31e4e5b5f8.tar.gz gitea-9911b66aea076347cfb271b12c90bc31e4e5b5f8.zip |
Be more lenient with label colors (#17752)
Accept 12-bit color specifications.
Diffstat (limited to 'models/issue_label.go')
-rw-r--r-- | models/issue_label.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/models/issue_label.go b/models/issue_label.go index 53d28c0596..0aea620773 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -22,7 +22,7 @@ import ( ) // LabelColorPattern is a regexp witch can validate LabelColor -var LabelColorPattern = regexp.MustCompile("^#[0-9a-fA-F]{6}$") +var LabelColorPattern = regexp.MustCompile("^#?(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})$") // Label represents a label of repository for issues. type Label struct { @@ -258,6 +258,23 @@ func NewLabel(label *Label) error { if !LabelColorPattern.MatchString(label.Color) { return fmt.Errorf("bad color code: %s", label.Color) } + + // normalize case + label.Color = strings.ToLower(label.Color) + + // add leading hash + if label.Color[0] != '#' { + label.Color = "#" + label.Color + } + + // convert 3-character shorthand into 6-character version + if len(label.Color) == 4 { + r := label.Color[1] + g := label.Color[2] + b := label.Color[3] + label.Color = fmt.Sprintf("#%c%c%c%c%c%c", r, r, g, g, b, b) + } + return newLabel(db.GetEngine(db.DefaultContext), label) } |