From cd276934fc86c7cb6c7ebc69cf0a6c27445bad0d Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 2 Aug 2024 01:51:59 +0200 Subject: cssvalues, sheet: fix some more case sensitivity bugs --- src/css/cssvalues.nim | 4 ++-- src/css/mediaquery.nim | 15 ++------------- src/css/sheet.nim | 5 ++--- test/layout/media-query.html | 2 +- todo | 1 - 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/css/cssvalues.nim b/src/css/cssvalues.nim index 9bb063b3..19b50966 100644 --- a/src/css/cssvalues.nim +++ b/src/css/cssvalues.nim @@ -1091,7 +1091,7 @@ func cssLineHeight(cval: CSSComponentValue): Opt[CSSLength] = of cttNumber: return cssLength(tok.nvalue * 100, "%") of cttIdent: - if tok.value == "normal": + if tok.value.equalsIgnoreCase("normal"): return ok(CSSLengthAuto) else: return cssLength(tok, has_auto = false) @@ -1161,7 +1161,7 @@ func cssImage(cval: CSSComponentValue): Opt[CSSContent] = if isToken(cval): #TODO bg-image only let tok = getToken(cval) - if tok.tokenType == cttIdent and tok.value == "none": + if tok.tokenType == cttIdent and tok.value.equalsIgnoreCase("none"): return ok(CSSContent(t: ContentImage, s: "")) let url = cssURL(cval) if url.isSome: diff --git a/src/css/mediaquery.nim b/src/css/mediaquery.nim index 277813b4..73649e8f 100644 --- a/src/css/mediaquery.nim +++ b/src/css/mediaquery.nim @@ -79,23 +79,12 @@ func `$`*(mf: MediaFeature): string = return "hover: " & $mf.b of mftPrefersColorScheme: return "prefers-color-scheme: " & $mf.b - of mftWidth: - result &= $mf.lengthrange.s.a - result &= " <" - if mf.lengthrange.aeq: - result &= "=" - result &= " width <" - if mf.lengthrange.beq: - result &= "=" - result &= " " - result &= $mf.lengthrange.s.b - of mftHeight: + of mftWidth, mftHeight: result &= $mf.lengthrange.s.a result &= " <" if mf.lengthrange.aeq: result &= "=" - result &= " width " - result &= "<" + result &= ' ' & $mf.t & " <" if mf.lengthrange.beq: result &= "=" result &= " " diff --git a/src/css/sheet.nim b/src/css/sheet.nim index 579e7f9e..bbf5e572 100644 --- a/src/css/sheet.nim +++ b/src/css/sheet.nim @@ -5,6 +5,7 @@ import css/cssvalues import css/mediaquery import css/selectorparser import html/catom +import utils/twtstr type CSSRuleBase* = ref object of RootObj @@ -193,8 +194,7 @@ proc addRule(stylesheet: CSSStylesheet; rule: CSSQualifiedRule) = inc stylesheet.len proc addAtRule(stylesheet: CSSStylesheet; atrule: CSSAtRule) = - case atrule.name - of "media": + if atrule.name.equalsIgnoreCase("media"): if atrule.oblock == nil: # invalid at-rule return @@ -212,7 +212,6 @@ proc addAtRule(stylesheet: CSSStylesheet; atrule: CSSAtRule) = media.children.addRule(CSSQualifiedRule(rule)) stylesheet.mqList.add(media) stylesheet.len = media.children.len - else: discard #TODO proc parseStylesheet*(ibuf: string; factory: CAtomFactory): CSSStylesheet = let raw = parseStylesheet(ibuf) diff --git a/test/layout/media-query.html b/test/layout/media-query.html index 1d09e25f..b450807f 100644 --- a/test/layout/media-query.html +++ b/test/layout/media-query.html @@ -1,5 +1,5 @@