Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ignore leading CR/LF characters in multipart body #120

Merged
merged 1 commit into from

6 participants

@bcherry

Hey there!

I've encountered a fatal bug in the multipart parser when a client submits a slightly malformed request. If the request begins with a new line, rather than beginning with the first boundary, the node-formidable parser will reject it and throw the 'parser error - 0 of X bytes parsed' error. This is simple enough to patch that I think it warrants inclusion.

The iOS library AFNetworking used to send this sort of request, although they've fixed it recently: AFNetworking/AFNetworking#134

Thanks!

@mattaylor

This also fixes problems with multipart uploads from unity3d.

This fix is magic, thanks. Is there a proper way to get this fix? I am using formidable within express - I change this section of code and it works, but how am I supposed to maintain that if I do an npm install? please excuse my ignorance. :)

Collaborator

If you could provide a test for this I'd merge it into master.

This is great, totally solves posting binary data to an express/node server from Unity 3D's WWW class. Thanks

@scitecwri

Seconded,

felixge, please merge this asap.

@svnlto svnlto merged commit b44d5a4 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 30, 2011
  1. @bcherry

    skip leading cr/lf

    bcherry authored
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 0 deletions.
  1. +5 −0 lib/multipart_parser.js
View
5 lib/multipart_parser.js
@@ -123,6 +123,11 @@ MultipartParser.prototype.write = function(buffer) {
case S.PARSER_UNINITIALIZED:
return i;
case S.START:
+ // skip leading CR/LF
+ if (c == CR || c == LF) {
+ continue;
+ }
+
index = 0;
state = S.START_BOUNDARY;
case S.START_BOUNDARY:
Something went wrong with that request. Please try again.