Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/prologue/core/form.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func parseFormPart*(body, contentType: string): FormPart =
tail = data[pos ..< ^2] # 2 because of protocol newline after content disposition body

if not head.startsWith("Content-Disposition"):
break
continue

for line in head.splitLines:
let header = line.parseHeader
Expand Down
Binary file added tests/unit/tunit_core/tunit_form
Binary file not shown.
18 changes: 17 additions & 1 deletion tests/unit/tunit_core/tunit_form.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ../../../src/prologue/core/form
import tables, strutils
import tables, strutils, strtabs

block:
const testmime =
Expand Down Expand Up @@ -40,3 +40,19 @@ block:
let formPart = parseFormPart(testmime, contenttype)
doAssert formPart.data["upload"].body.len == testfile.len
doAssert formPart.data["upload"].body == testfile

block:
# Test for file input field (issue: multipart/form-data not working)
# This tests that file inputs with filename parameter work correctly
const testmime =
"------WebKitFormBoundary7MA4YWxkTrZu0gW\13\10" &
"Content-Disposition: form-data; name=\"myfile\"; filename=\"test.txt\"\13\10" &
"Content-Type: text/plain\13\10" &
"\13\10" &
"Hello World\13\10" &
"------WebKitFormBoundary7MA4YWxkTrZu0gW--\13\10"
const contenttype = "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
let formPart = parseFormPart(testmime, contenttype)
doAssert formPart.data.contains("myfile"), "myfile field should be present"
doAssert formPart.data["myfile"].body == "Hello World"
doAssert formPart.data["myfile"].params.getOrDefault("filename", "") == "test.txt"