mirror of
https://github.com/denoland/deno.git
synced 2025-01-22 15:10:44 -05:00
Fix denoland/deno_std#409 handle multipart header in mime reader (denoland/deno_std#415)
Original: 92c26cc331
This commit is contained in:
parent
715fe3300e
commit
ef4fd3d4ca
2 changed files with 35 additions and 1 deletions
|
@ -83,7 +83,8 @@ export class TextProtoReader {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
let [kv, err] = await this.readLineSlice(); // readContinuedLineSlice
|
let [kv, err] = await this.readLineSlice(); // readContinuedLineSlice
|
||||||
if (kv.byteLength == 0) {
|
|
||||||
|
if (kv.byteLength === 0) {
|
||||||
return [m, err];
|
return [m, err];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,10 +141,15 @@ export class TextProtoReader {
|
||||||
// Go's len(typed nil) works fine, but not in JS
|
// Go's len(typed nil) works fine, but not in JS
|
||||||
return [new Uint8Array(0), err];
|
return [new Uint8Array(0), err];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid the copy if the first call produced a full line.
|
// Avoid the copy if the first call produced a full line.
|
||||||
if (line == null && !more) {
|
if (line == null && !more) {
|
||||||
|
if (this.skipSpace(l) === 0) {
|
||||||
|
return [new Uint8Array(0), null];
|
||||||
|
}
|
||||||
return [l, null];
|
return [l, null];
|
||||||
}
|
}
|
||||||
|
|
||||||
line = append(line, l);
|
line = append(line, l);
|
||||||
if (!more) {
|
if (!more) {
|
||||||
break;
|
break;
|
||||||
|
@ -151,4 +157,15 @@ export class TextProtoReader {
|
||||||
}
|
}
|
||||||
return [line, null];
|
return [line, null];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skipSpace(l: Uint8Array): number {
|
||||||
|
let n = 0;
|
||||||
|
for (let i = 0; i < l.length; i++) {
|
||||||
|
if (l[i] === charCode(" ") || l[i] === charCode("\t")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,3 +165,20 @@ test({
|
||||||
assert(err instanceof ProtocolError);
|
assert(err instanceof ProtocolError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test({
|
||||||
|
name: "[textproto] #409 issue : multipart form boundary",
|
||||||
|
async fn(): Promise<void> {
|
||||||
|
const input = [
|
||||||
|
"Accept: */*\r\n",
|
||||||
|
'Content-Disposition: form-data; name="test"\r\n',
|
||||||
|
" \r\n",
|
||||||
|
"------WebKitFormBoundaryimeZ2Le9LjohiUiG--\r\n\n"
|
||||||
|
];
|
||||||
|
const r = reader(input.join(""));
|
||||||
|
let [m, err] = await r.readMIMEHeader();
|
||||||
|
assertEquals(m.get("Accept"), "*/*");
|
||||||
|
assertEquals(m.get("Content-Disposition"), 'form-data; name="test"');
|
||||||
|
assert(!err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue