diff options
author | bptato <nincsnevem662@gmail.com> | 2022-07-23 18:38:49 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-07-23 18:38:49 +0200 |
commit | 0bf3beb0a40bf58c627ccc79f46e7c20ad857a47 (patch) | |
tree | 4ad91eb3e71d072373d6502ed6e11b7b33bfa186 /src/html | |
parent | e7b53775a3f52cb5d8da865213c5dc38b954e33c (diff) | |
download | chawan-0bf3beb0a40bf58c627ccc79f46e7c20ad857a47.tar.gz |
Fix an infinite loop in getElementById
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 2117e6f4..98ed023b 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -613,19 +613,12 @@ func newAttr*(parent: Element, key, value: string): Attr = result.name = key result.value = value -func getElementById*(document: Document, id: string): Element = +func getElementById*(node: Node, id: string): Element = if id.len == 0: return nil - var stack: seq[Element] - for child in document.children_rev: - stack.add(child) - while stack.len > 0: - let element = stack.pop() - if element.id == id: - return element - for child in document.children_rev: - stack.add(child) - return nil + for child in node.elements: + if child.id == id: + return child func getElementsByTag*(document: Document, tag: TagType): seq[Element] = for element in document.elements(tag): |