-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new line issues when parsing multipart/form-data? #3768
Comments
Not sure if this is a bug: https://tools.ietf.org/html/rfc7231#section-3.1.1.4 Looks like CRLF is required for multipart messages. |
So my text file (the one that fails the test) is invalid because it only contains LF? When I encountered this bug, I passed in a .txt file I created from TextEdit. The parser couldn’t read it. If CRLF is required, how can I get my text files to include CRLF on my Mac? Seems a bit annoying to have to rework the files you pass to the parser just to get it to read your files. In that case, I’m screwed because I’m on a Mac and it uses LF. |
I agree with @artisonian. I don't really think it's a bug. The file named sample.txt, used to test the method The common syntax for multipart HTTP bodies can be found in the RFC 2046, and a complex example of a multipart HTTP body can be seen in the RFC 2049. |
deno authors, I took another look at the way I was parsing my file. Below are my findings and the steps I took. I am running macOS Catalina Version 10.15.2.
import { BufReader } from "https://deno.land/std@v0.31.0/io/bufio.ts";
import { MultipartReader } from "https://deno.land/std@v0.31.0/mime/multipart.ts";
import { serve } from "https://deno.land/std@v0.31.0/http/server.ts";
const s = serve({ port: 1447 });
console.log("http://localhost:1447/");
for await (const req of s) {
const readBody = await Deno.readAll(req.body);
const br = new BufReader(new Deno.Buffer(readBody));
const line: any = await br.readLine();
const boundary = new TextDecoder().decode(line.line) + "\r\n";
const mr = new MultipartReader(
br,
boundary
);
const encoder = new TextEncoder();
try {
const form = await mr.readForm(20);
console.log(form);
} catch (error) {
console.log(error.stack);
}
req.respond({ body: "done" });
}
Below is the error I receive after running the
Now what's strange about this finding is that I've cloned the deno repo and changed my Below is what my tweaked
Below are my files that I'm currently using to debug the "issue". Sorry btw, GitHub doesn't like test.txt @artisonian / @rafaelvargas , like I said. I'm screwed... as well as others whose machines and editors don't add CRLF. Unless one of you have a proposed solution to handle this, I'm proposing that |
Sounds like there are two things going on:
|
Thanks for the response. I tried your Gist. It works. I took a look at the way I'm parsing the boundary and the way you're parsing the boundary. Here is what I found:
The issue is in the way I'm parsing the boundary. If it's ok with you, I'd like to take your Gist and create documentation on how to use the |
Feel free to use the gist. Also, I commented on #3763 which asks for documentation too. |
not an issue. was using the |
i noticed something strange while trying to parse a multipart server request body. i kept getting the
UnexpectedEOFError: Unexpected EOF
error when usingMultipartReader
inmultipart.ts
. example code that fails is below:having encountered this and not being able to debug it, i decided to clone deno and run the
multipart_test.ts
file. it worked. i then checked thesample.txt
file it uses and saw the^M
characters. i deleted the characters, ran the tests again and they failed. below is a screenshot of the files i tested. the top file fails and the bottom file passes.so, i think there is an issue around the way the
MultipartReader
reads new line characters in a multipart request body. i've traced the issue to this line ...deno/std/mime/multipart.ts
Line 348 in 9f1e423
... and could not find a solution.
The text was updated successfully, but these errors were encountered: