about summary refs log tree commit diff stats
path: root/src/types
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-13 16:43:58 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-13 16:43:58 +0200
commit02227d9c73c25cebf17d86ebc5d8468494093a16 (patch)
treee8f89b52c9e9b767c17dc1fca4e430775caf6de9 /src/types
parenteb83e61ca783a72c4f4fb954a8e9d60014007c98 (diff)
downloadchawan-02227d9c73c25cebf17d86ebc5d8468494093a16.tar.gz
color: fix parseLegacyColor bugs
* lower-case the input string.
* do not fall back to black on error. (i.e. remove the special cased
  parseLegacyColor0 in cascade)
Diffstat (limited to 'src/types')
-rw-r--r--src/types/color.nim8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/types/color.nim b/src/types/color.nim
index 8f01309f..48f9d9e7 100644
--- a/src/types/color.nim
+++ b/src/types/color.nim
@@ -460,10 +460,7 @@ func parseRGBAColor*(s: string): Option[RGBAColor] =
     return parseHexColor(s[2..^1])
   return parseHexColor(s)
 
-func parseLegacyColor0*(s: string): RGBColor =
-  if s == "": return
-  let s = s.strip(chars = AsciiWhitespace)
-  if s == "transparent": return
+func parseLegacyColor0(s: string): RGBColor =
   if s in ColorsRGB:
     return ColorsRGB[s]
   block hex:
@@ -502,6 +499,9 @@ func parseLegacyColor0*(s: string): RGBColor =
 func parseLegacyColor*(s: string): JSResult[RGBColor] =
   if s == "":
     return err(newTypeError("Color value must not be the empty string"))
+  let s = s.strip(chars = AsciiWhitespace).toLowerAscii()
+  if s == "transparent":
+    return err(newTypeError("Color must not be transparent"))
   return ok(parseLegacyColor0(s))
 
 proc toJS*(ctx: JSContext, rgb: RGBColor): JSValue =