about summary refs log tree commit diff stats
path: root/src/loader
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-08-17 16:57:18 +0200
committerbptato <nincsnevem662@gmail.com>2024-08-17 16:57:18 +0200
commit30920fe12cbc6ab72078a68e308931bf865ede26 (patch)
treebb93a23bae417bb6196a634dab238628bffadebd /src/loader
parentf5f841dc7528098c2a07bd06280fa9d1c4ea3164 (diff)
downloadchawan-30920fe12cbc6ab72078a68e308931bf865ede26.tar.gz
loader: fix crash on empty data URLs
Diffstat (limited to 'src/loader')
-rw-r--r--src/loader/loader.nim9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index c9025153..c40c3cad 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -414,10 +414,17 @@ proc loadDataSend(ctx: LoaderContext; handle: LoaderHandle; s, ct: string) =
   handle.sendResult(0)
   handle.sendStatus(200)
   handle.sendHeaders(newHeaders({"Content-Type": ct}))
+  let output = handle.output
+  if s.len == 0:
+    if output.suspended:
+      output.istreamAtEnd = true
+      ctx.outputMap[output.ostream.fd] = output
+    else:
+      output.oclose()
+    return
   let buffer = newLoaderBuffer(size = s.len)
   buffer.len = s.len
   copyMem(buffer.page, unsafeAddr s[0], s.len)
-  let output = handle.output
   case ctx.pushBuffer(output, buffer, 0)
   of pbrUnregister:
     if output.registered: