about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-07-23 18:38:49 +0200
committerbptato <nincsnevem662@gmail.com>2022-07-23 18:38:49 +0200
commit0bf3beb0a40bf58c627ccc79f46e7c20ad857a47 (patch)
tree4ad91eb3e71d072373d6502ed6e11b7b33bfa186 /src/html
parente7b53775a3f52cb5d8da865213c5dc38b954e33c (diff)
downloadchawan-0bf3beb0a40bf58c627ccc79f46e7c20ad857a47.tar.gz
Fix an infinite loop in getElementById
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim15
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):