busboy
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -22,2 +22,4 @@ var fs = require('fs'), | ||
this.parseHeaders(opts.headers); | ||
else | ||
throw new Error('Missing Content-Type'); | ||
} | ||
@@ -24,0 +26,0 @@ inherits(Busboy, WritableStream); |
@@ -9,4 +9,3 @@ // TODO: | ||
var ReadableStream = require('stream').Readable || require('readable-stream'), | ||
inherits = require('util').inherits, | ||
path = require('path'); | ||
inherits = require('util').inherits; | ||
@@ -16,3 +15,4 @@ var Dicer = require('dicer'); | ||
var parseParams = require('../utils').parseParams, | ||
decodeText = require('../utils').decodeText; | ||
decodeText = require('../utils').decodeText, | ||
basename = require('../utils').basename; | ||
@@ -35,3 +35,3 @@ var RE_BOUNDARY = /^boundary$/i, | ||
headers = cfg.headers, | ||
parsedConType = cfg.parsedConType, | ||
parsedConType = cfg.parsedConType || [], | ||
defCharset = cfg.defCharset || 'utf8', | ||
@@ -85,2 +85,3 @@ fileopts = (typeof cfg.fileHwm === 'number' | ||
parserCfg.highWaterMark = cfg.highWaterMark; | ||
this.parser = new Dicer(parserCfg); | ||
@@ -107,12 +108,15 @@ this.parser.on('drain', function() { | ||
parsed = parseParams(header['content-type'][0]); | ||
contype = parsed[0].toLowerCase(); | ||
for (i = 0, len = parsed.length; i < len; ++i) { | ||
if (RE_CHARSET.test(parsed[i][0])) { | ||
charset = parsed[i][1].toLowerCase(); | ||
break; | ||
if (parsed[0]) { | ||
contype = parsed[0].toLowerCase(); | ||
for (i = 0, len = parsed.length; i < len; ++i) { | ||
if (RE_CHARSET.test(parsed[i][0])) { | ||
charset = parsed[i][1].toLowerCase(); | ||
break; | ||
} | ||
} | ||
} | ||
} else | ||
} | ||
if (contype === undefined) | ||
contype = 'text/plain'; | ||
if (charset === undefined) | ||
@@ -129,3 +133,3 @@ charset = defCharset; | ||
else if (RE_FILENAME.test(parsed[i][0])) | ||
filename = path.basename(decodeText(parsed[i][1], 'binary', 'utf8')); | ||
filename = basename(decodeText(parsed[i][1], 'binary', 'utf8')); | ||
} | ||
@@ -132,0 +136,0 @@ } else |
@@ -7,3 +7,3 @@ var jsencoding = require('../deps/encoding/encoding'); | ||
} | ||
exports.parseParams = function(str) { | ||
function parseParams(str) { | ||
var res = [], | ||
@@ -77,18 +77,16 @@ state = 'key', | ||
} | ||
if (tmp.length) { | ||
if (charset) { | ||
tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer), | ||
'binary', | ||
charset); | ||
} | ||
if (res[p] === undefined) | ||
res[p] = tmp; | ||
else | ||
res[p][1] = tmp; | ||
if (charset) { | ||
tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer), | ||
'binary', | ||
charset); | ||
} | ||
if (res[p] === undefined) | ||
res[p] = tmp; | ||
else | ||
res[p][1] = tmp; | ||
return res; | ||
}; | ||
exports.parseParams = parseParams; | ||
exports.Decoder = Decoder; | ||
@@ -107,2 +105,3 @@ function decodeText(text, textEncoding, destEncoding) { | ||
var HEX = [ | ||
@@ -156,1 +155,32 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
}; | ||
exports.Decoder = Decoder; | ||
var RE_SPLIT_POSIX = | ||
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/, | ||
RE_SPLIT_DEVICE = | ||
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/, | ||
RE_SPLIT_WINDOWS = | ||
/^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/; | ||
function splitPathPosix(filename) { | ||
return RE_SPLIT_POSIX.exec(filename).slice(1); | ||
} | ||
function splitPathWindows(filename) { | ||
// Separate device+slash from tail | ||
var result = RE_SPLIT_DEVICE.exec(filename), | ||
device = (result[1] || '') + (result[2] || ''), | ||
tail = result[3] || ''; | ||
// Split the tail into dir, basename and extension | ||
var result2 = RE_SPLIT_WINDOWS.exec(tail), | ||
dir = result2[1], | ||
basename = result2[2], | ||
ext = result2[3]; | ||
return [device, dir, basename, ext]; | ||
} | ||
function basename(path) { | ||
var f = splitPathPosix(path)[2]; | ||
if (f === path) | ||
f = splitPathWindows(path)[2]; | ||
return f; | ||
} | ||
exports.basename = basename; |
{ "name": "busboy", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"author": "Brian White <mscdex@mscdex.net>", | ||
@@ -4,0 +4,0 @@ "description": "A streaming parser for HTML form data for node.js", |
@@ -42,3 +42,3 @@ Description | ||
}); | ||
busboy.on('field', function(fieldname, val, valTruncated, keyTruncated) { | ||
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) { | ||
console.log('Field [' + fieldname + ']: value: ' + inspect(val)); | ||
@@ -125,3 +125,3 @@ }); | ||
}); | ||
busboy.on('field', function(fieldname, val, valTruncated, keyTruncated) { | ||
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) { | ||
console.log('Field [' + fieldname + ']: value: ' + inspect(val)); | ||
@@ -128,0 +128,0 @@ }); |
@@ -155,2 +155,21 @@ var Busboy = require('..'); | ||
}, | ||
{ source: [ | ||
['------WebKitFormBoundaryTB2MiQ36fnSJlrhY', | ||
'Content-Disposition: form-data; name="cont"', | ||
'Content-Type: ', | ||
'', | ||
'some random content', | ||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY', | ||
'Content-Disposition: ', | ||
'', | ||
'some random pass', | ||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY--' | ||
].join('\r\n') | ||
], | ||
boundary: '----WebKitFormBoundaryTB2MiQ36fnSJlrhY', | ||
expected: [ | ||
['field', 'cont', 'some random content', false, false] | ||
], | ||
what: 'Empty content-type and empty content-disposition' | ||
}, | ||
]; | ||
@@ -157,0 +176,0 @@ |
@@ -14,2 +14,6 @@ var parseParams = require('../lib/utils').parseParams; | ||
}, | ||
{ source: 'text/plain; encoding=', | ||
expected: ['text/plain', ['encoding', '']], | ||
what: 'Unquoted empty string' | ||
}, | ||
{ source: 'text/plain; encoding="utf8"', | ||
@@ -23,2 +27,6 @@ expected: ['text/plain', ['encoding', 'utf8']], | ||
}, | ||
{ source: 'text/plain; encoding=""', | ||
expected: ['text/plain', ['encoding', '']], | ||
what: 'Quoted empty string' | ||
}, | ||
{ source: 'text/plain; encoding="utf8";\t foo=bar;test', | ||
@@ -60,2 +68,6 @@ expected: ['text/plain', ['encoding', 'utf8'], ['foo', 'bar'], 'test'], | ||
}, | ||
{ source: 'multipart/form-data; charset=utf-8; boundary=0xKhTmLbOuNdArY', | ||
expected: ['multipart/form-data', ['charset', 'utf-8'], ['boundary', '0xKhTmLbOuNdArY']], | ||
what: 'Multiple non-quoted parameters' | ||
}, | ||
].forEach(function(v) { | ||
@@ -62,0 +74,0 @@ var result = parseParams(v.source), |
Sorry, the diff of this file is too big to display
673024
5497