about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-07-15 20:12:11 +0200
committerbptato <nincsnevem662@gmail.com>2023-07-15 20:12:11 +0200
commitdc934380de353d16ff62c633ff949fb85b30fd13 (patch)
treeb831b0633da44cf059b735ae8b2f0c4f9e311a88 /src/html
parent9aa9ecd2d2c5048ac3057aeee28b1e42ce4be0d8 (diff)
downloadchawan-dc934380de353d16ff62c633ff949fb85b30fd13.tar.gz
htmlparser: check required callbacks
Diffstat (limited to 'src/html')
-rw-r--r--src/html/htmlparser.nim13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim
index e72f897e..442068ad 100644
--- a/src/html/htmlparser.nim
+++ b/src/html/htmlparser.nim
@@ -2671,10 +2671,23 @@ proc bomSniff(inputStream: Stream): Charset =
     else:
       inputStream.setPosition(0)
 
+# Any of these pointers being nil would later result in a crash.
+proc checkCallbacks(dombuilder: DOMBuilder) =
+  doAssert dombuilder.getTemplateContent != nil
+  doAssert dombuilder.getParentNode != nil
+  doAssert dombuilder.getLocalName != nil
+  doAssert dombuilder.createElement != nil
+  doAssert dombuilder.createComment != nil
+  doAssert dombuilder.createDocumentType != nil
+  doAssert dombuilder.insertBefore != nil
+  doAssert dombuilder.insertText != nil
+  doAssert dombuilder.remove != nil
+
 proc parseHTML*[Handle](inputStream: Stream, dombuilder: DOMBuilder[Handle],
     opts: HTML5ParserOpts[Handle]) =
   ## Parse an HTML document, using the DOMBuilder object `dombuilder`, and
   ## parser options `opts`.
+  dombuilder.checkCallbacks()
   var charsetStack: seq[Charset]
   for i in countdown(opts.charsets.high, 0):
     charsetStack.add(opts.charsets[i])