Skip to content

parsing does not complete with a multiline form field #277

Description

@efriends-tom

It seems that form data with multiline strings is not parsed in the "field" handler.

Here is a short program to illustrate:

var multiparty = require('multiparty');
var http = require('http');
var util = require('util');

http.createServer(function(req, res) {
  if (req.url === '/test' && req.method === 'POST') {
    console.log("about to parse test request");
    let form = new multiparty.Form();
    form.on("error", (err) => { console.log("form error " + err)});
    //form.on("part", (part) => { console.log(`part ${part.name}`); part.resume(); });
    form.on("field", (name, value) => { console.log(`field ${name} -> ${value}`);});
    form.on("close", () => { console.log("form was closed"); });
    form.parse(req);
  }

  res.statusCode = 200;
  res.end("OK");

}).listen(8080);
console.log("listening on port 8080");

When I provide a file with two lines (separated with CR LF),
curl -X POST http://localhost:8080/test -F "note=<twolines.txt"
I get only
about to parse test request
... neither the field nor the "close" handler is called, I would expect a multiline field to be output and the form closed.

Note: When I run curl providing a text file with a single line, I get the expected output:
curl -X POST http://localhost:8080/test -F "note=<oneline.txt"
about to parse test request
field note -> This is the only line
form was closed

When I activate the "part" handler, the behaviour is the same
When I activate the "part" handler and remove the "field" handler, the close handler is called again (after the part handler, as expected)

How can I parse multiline form fields?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions