diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-31 15:07:42 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-31 15:07:42 +0100 |
commit | 362e934deb77ae12e2a26d88f597c046eb13be3d (patch) | |
tree | 935e44cb65d3ace9f435b316c400325d949ddb4c /src/css | |
parent | 1c61efbcba2e4d28f92ad82c1eb0bb09a4cfcf5b (diff) | |
download | chawan-362e934deb77ae12e2a26d88f597c046eb13be3d.tar.gz |
selectorparser: accept less invalid selectors
Diffstat (limited to 'src/css')
-rw-r--r-- | src/css/selectorparser.nim | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/css/selectorparser.nim b/src/css/selectorparser.nim index 1e0d1a66..90214a13 100644 --- a/src/css/selectorparser.nim +++ b/src/css/selectorparser.nim @@ -87,7 +87,14 @@ proc `$`*(sel: Selector): string = of ID_SELECTOR: return '#' & sel.id of ATTR_SELECTOR: - return '[' & sel.attr & sel.rel & sel.value & ']' + var rel = "" + if sel.rel == '=': + rel = "=" + elif sel.rel == ' ': + discard + else: + rel = sel.rel & '=' + return '[' & sel.attr & rel & sel.value & ']' of CLASS_SELECTOR: return '.' & sel.class of UNIVERSAL_SELECTOR: @@ -432,9 +439,14 @@ func parseSelectors*(cvals: seq[CSSComponentValue]): seq[ComplexSelector] = {.ca if state.combinator.ct == DESCENDANT_COMBINATOR: # otherwise it's an invalid combinator state.selectors[^1].add(state.combinator.csels[0]) - else: + else: + state.selectors.setLen(0) + elif state.combinator.csels[^1].len != 0: state.selectors[^1].add(state.combinator) state.combinator = nil + if state.selectors.len > 0 and state.selectors[^1].len == 0: + # invalid selector + state.selectors.setLen(0) return state.selectors proc parseSelectors*(stream: Stream): seq[ComplexSelector] = |