Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function plugin(formidable, options) {
/* istanbul ignore next */
const self = this || formidable;

if (/json/i.test(self.headers['content-type'])) {
if (/^[^;]*json/i.test(self.headers['content-type'])) {
init.call(self, self, options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function plugin(formidable, options) {
const self = this || formidable;

// NOTE: we (currently) support both multipart/form-data and multipart/related
const multipart = /multipart/i.test(self.headers['content-type']);
const multipart = /^[^;]*multipart/i.test(self.headers['content-type']);

if (multipart) {
const m = self.headers['content-type'].match(
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/octetstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function plugin(formidable, options) {
/* istanbul ignore next */
const self = this || formidable;

if (/octet-stream/i.test(self.headers['content-type'])) {
if (/^[^;]*octet-stream/i.test(self.headers['content-type'])) {
await init.call(self, self, options);
}
return self;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function plugin(formidable, options) {
/* istanbul ignore next */
const self = this || formidable;

if (/urlencoded/i.test(self.headers['content-type'])) {
if (/^[^;]*urlencoded/i.test(self.headers['content-type'])) {
init.call(self, self, options);
}
return self;
Expand Down
13 changes: 13 additions & 0 deletions test/fixture/http/misc/boundary-substring-json.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
POST /upload HTTP/1.1
Host: localhost:8080
Content-Type: multipart/form-data; boundary=uj05Dyqd7Fd5aqAJnK1j9WeJSONmNy5vSGbM1oLf
Content-Length: 211

--uj05Dyqd7Fd5aqAJnK1j9WeJSONmNy5vSGbM1oLf
Content-Disposition: form-data; filename="plain.txt"; name="upload"
Content-Type: text/plain

I am a plain text file

--uj05Dyqd7Fd5aqAJnK1j9WeJSONmNy5vSGbM1oLf--

10 changes: 10 additions & 0 deletions test/fixture/js/misc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
const boundary_substring_json = [
{
type: 'file',
name: 'upload',
originalFilename: 'plain.txt',
fixture: 'boundary-substring-json',
},
];

const empty_http = [];
const empty_urlencoded_http = [];
const empty_multipart_http = [];
const empty_multipart2_http = [];
const _minimal_http = [];

export {
boundary_substring_json,
empty_http,
empty_urlencoded_http,
empty_multipart_http,
Expand Down
53 changes: 30 additions & 23 deletions test/integration/fixtures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,36 @@ test('fixtures', (done) => {
const fixture = fixtureWithName.fixture;

uploadFixture(fixtureName, (err, parts) => {
if (err) {
err.fixtureName = fixtureName;
throw err;
}
try {
if (err) {
err.fixtureName = fixtureName;
throw err;
}

fixture.forEach((expectedPart, i) => {
const parsedPart = parts[i];
strictEqual(parsedPart.type, expectedPart.type);
strictEqual(parsedPart.name, expectedPart.name);

if (parsedPart.type === 'file') {
const file = parsedPart.value;
strictEqual(file.originalFilename, expectedPart.originalFilename,
`${JSON.stringify([expectedPart, file])}`);

if (expectedPart.sha1) {
strictEqual(
file.hash,
expectedPart.sha1,
`SHA1 error ${file.originalFilename} on ${file.filepath} ${JSON.stringify([expectedPart, file])}`,
);
fixture.forEach((expectedPart, i) => {
const parsedPart = parts[i];
strictEqual(parsedPart.type, expectedPart.type);
strictEqual(parsedPart.name, expectedPart.name);

if (parsedPart.type === 'file') {
const file = parsedPart.value;
strictEqual(file.originalFilename, expectedPart.originalFilename,
`${JSON.stringify([expectedPart, file])}`);

if (expectedPart.sha1) {
strictEqual(
file.hash,
expectedPart.sha1,
`SHA1 error ${file.originalFilename} on ${file.filepath} ${JSON.stringify([expectedPart, file])}`,
);
}
}
}
});
});
} catch (e) {
server.close();
done(e);
throw e;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new try-catch is because otherwise the test was just timing out rather than reporting the error.

}

testNext(results);
});
Expand All @@ -93,7 +99,6 @@ test('fixtures', (done) => {
uploadDir: UPLOAD_DIR,
hashAlgorithm: 'sha1',
});
form.parse(req);

function callback(...args) {
const realCallback = cb;
Expand All @@ -116,6 +121,8 @@ test('fixtures', (done) => {
res.end();
callback(null, parts);
});

form.parse(req);
});

const socket = createConnection(PORT);
Expand Down