From b599aac3ae05b96938b6e8557c87d5345378ba18 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 31 Mar 2024 17:23:54 +0200 Subject: [PATCH] Support four-value syntax for CSS hex color Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color --- css/handlers.go | 2 +- sanitize_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/css/handlers.go b/css/handlers.go index f8b8b61..41a00c8 100644 --- a/css/handlers.go +++ b/css/handlers.go @@ -291,7 +291,7 @@ var ( Font = regexp.MustCompile(`^('[a-z \-]+'|[a-z \-]+)$`) Grayscale = regexp.MustCompile(`^grayscale\(([0-9]{1,2}|100)%\)$`) GridTemplateAreas = regexp.MustCompile(`^['"]?[a-z ]+['"]?$`) - HexRGB = regexp.MustCompile(`^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$`) + HexRGB = regexp.MustCompile(`^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$`) HSL = regexp.MustCompile(`^hsl\([ ]*([012]?[0-9]{1,2}|3[0-5][0-9]|360),[ ]*([0-9]{0,2}|100)\%,[ ]*([0-9]{0,2}|100)\%\)$`) HSLA = regexp.MustCompile(`^hsla\(([ ]*[012]?[0-9]{1,2}|3[0-5][0-9]|360),[ ]*([0-9]{0,2}|100)\%,[ ]*([0-9]{0,2}|100)\%,[ ]*(1|1\.0|0|(0\.[0-9]+))\)$`) HueRotate = regexp.MustCompile(`^hue-rotate\(([12]?[0-9]{1,2}|3[0-5][0-9]|360)?\)$`) diff --git a/sanitize_test.go b/sanitize_test.go index c81aa8b..13feecf 100644 --- a/sanitize_test.go +++ b/sanitize_test.go @@ -2028,6 +2028,10 @@ func TestDefaultStyleHandlers(t *testing.T) { in: `
`, expected: `
`, }, + { + in: `
`, + expected: `
`, + }, { in: `
`, expected: `
`,