grafana/k6-jslib-formdata

FormData is broken as it expects the property "filename" to exist on an empty p.file

rniedosmialek opened this issue · 3 comments

Ran into an issue with FormData producing the following error.

ERRO[0309] TypeError: Cannot read property 'filename' of undefined

I found this condition is accessing "filename" with out evaluating p.file even exists

if (p.file.filename) { cd += '; filename="' + p.file.filename.replace(/"/g,'%22') + '"'; }

I had to update the condition to test for the existance of both.

// Check if p.file and p.file.filename exist before using if (p.file && p.file.filename) { cd += '; filename="' + p.file.filename.replace(/"/g,'%22') + '"'; }

@olegbespalov Is any updates here?

Hey @rniedosmialek @PeaceDate

Sorry, it went off my radars 😢

It sounds like a bug on this corner case. Will it work for you if you manually form the file data, like:

fd.append('aTestFile', { data: null, filename: '', content_type: 'application/octet-stream' });

I'm curious to learn more about the case. So you want to test the multipart request where nothing passed, right?

In other words, what do you think the request should look like? Is it something like below?

POST /submit-form HTTP/1.1
Host: example.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: 342

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="text"

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename=""
Content-Type: application/octet-stream

------WebKitFormBoundary7MA4YWxkTrZu0gW--

@olegbespalov This is helps for now
fd.append('aTestFile', { data: null, filename: '', content_type: 'application/octet-stream' });