Skip to content

Commit 0358f0e

Browse files
committed
Fix: Don't let the world know how stupid IE is
IE6 (and up?) actually sends the full path of the local file that is being uploaded rather than just the name of it. This patch strips of any path information from the filename.
1 parent c9df5fe commit 0358f0e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/formidable/incoming_form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ IncomingForm.prototype._initMultipart = function(boundary) {
245245
}
246246

247247
if (m = headerValue.match(/filename="([^"]+)"/i)) {
248-
part.filename = m[1];
248+
part.filename = m[1].substr(m[1].lastIndexOf('\\') + 1);
249249
}
250250
} else if (headerField == 'content-type') {
251251
part.mime = headerValue;

test/simple/test-incoming-form.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,12 @@ test(function _initMultipart() {
378378
gently.expect(form, 'onPart', function(part) {
379379
assert.deepEqual
380380
( part.headers
381-
, { 'content-disposition': 'form-data; name="field2"; filename="file1.txt"'
381+
, { 'content-disposition': 'form-data; name="field2"; filename="C:\\Documents and Settings\\IE\\Must\\Die\\Sunset.jpg"'
382382
, 'content-type': 'text/plain'
383383
}
384384
);
385385
assert.equal(part.name, 'field2');
386-
assert.equal(part.filename, 'file1.txt');
386+
assert.equal(part.filename, 'Sunset.jpg');
387387
assert.equal(part.mime, 'text/plain');
388388

389389
gently.expect(part, 'emit', function(event, b) {
@@ -398,7 +398,7 @@ test(function _initMultipart() {
398398

399399
PARSER.onPartBegin();
400400
PARSER.onHeaderField(new Buffer('content-disposition'), 0, 19);
401-
PARSER.onHeaderValue(new Buffer('form-data; name="field2"; filename="file1.txt"'), 0, 46);
401+
PARSER.onHeaderValue(new Buffer('form-data; name="field2"; filename="C:\\Documents and Settings\\IE\\Must\\Die\\Sunset.jpg"'), 0, 85);
402402
PARSER.onHeaderField(new Buffer('Content-Type'), 0, 12);
403403
PARSER.onHeaderValue(new Buffer('text/plain'), 0, 10);
404404
PARSER.onPartData(new Buffer('... contents of file1.txt ...'), 0, 29);

0 commit comments

Comments
 (0)