Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

messy

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messy - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

61

lib/foldHeaderLine.js

@@ -1,45 +0,30 @@

// Butchered from https://github.com/andris9/mimelib/blob/master/mime-functions.js:
module.exports = function foldHeaderLine(str, maxLength, foldAnywhere, afterSpace) {
var curpos = 0,
response = "",
lf;
module.exports = function foldHeaderLine(str, maxLength, firstLineMaxLength) {
maxLength = maxLength || 78;
// return original if no need to fold
if (str.length <= maxLength) {
firstLineMaxLength = firstLineMaxLength || maxLength;
if (str.length <= firstLineMaxLength) {
return str;
}
var result = '',
currentLineStartIndex = 0,
lastSpaceIndex = -1,
lastSpace,
isFirstLine = true;
for (var i = 0 ; i < str.length ; i += 1) {
if (/^\s$/.test(str[i])) {
lastSpaceIndex = i;
lastSpace = str[i];
}
var line;
while (curpos < str.length) {
// read in <maxLength> bytes and try to fold it
line = str.substr(curpos, maxLength);
if (foldAnywhere) {
response += line;
if (curpos + maxLength < str.length) {
response += "\r\n";
}
} else {
lf = line.lastIndexOf(" ");
if (lf <= 0) {
lf = line.lastIndexOf("\t");
}
if (line.length >= maxLength && lf > 0) {
if (afterSpace) {
// move forward until line end or no more \s and \t
while (lf < line.length && (line.charAt(lf) === " " || line.charAt(lf) === "\t")) {
lf += 1;
}
}
response += line.substr(0, lf) + "\r\n";
curpos -= line.substr(lf).length;
} else {
response += line;
}
if (i - currentLineStartIndex >= (isFirstLine ? firstLineMaxLength : maxLength - 1) && lastSpaceIndex !== -1) {
result += (isFirstLine ? '' : '\r\n' + lastSpace) + str.substring(currentLineStartIndex, lastSpaceIndex);
isFirstLine = false;
i = lastSpaceIndex;
currentLineStartIndex = i + 1;
lastSpaceIndex = -1;
}
curpos += line.length;
}
return response;
if (i > currentLineStartIndex) {
result += (isFirstLine ? '' : '\r\n' + lastSpace) + str.substring(currentLineStartIndex, str.length);
}
return result;
};

@@ -280,3 +280,3 @@ var foldHeaderLine = require('./foldHeaderLine'),

this.valuesByName[lowerCaseHeaderName].forEach(function (value) {
result += foldHeaderLine(formatHeaderName(lowerCaseHeaderName) + ': ' + value + "\r\n", maxLineLength);
result += formatHeaderName(lowerCaseHeaderName) + ': ' + foldHeaderLine(value, maxLineLength, maxLineLength - lowerCaseHeaderName.length - 2) + '\r\n';
});

@@ -283,0 +283,0 @@ }, this);

@@ -84,6 +84,5 @@ /*global unescape*/

match;
// TODO: Basic validation of end marker etc.
while ((match = boundaryRegExp.exec(bodyAsString))) {
var whitespaceBefore = match[1],
endMarker = match[2],
index = match.index;
var index = match.index;
if (startIndex !== -1) {

@@ -90,0 +89,0 @@ parts.push(new Message(this.body.slice(startIndex, index)));

{
"name": "messy",
"version": "3.0.1",
"version": "3.1.0",
"description": "Object model for HTTP and RFC822 messages",

@@ -32,4 +32,3 @@ "main": "lib/index.js",

"mocha": "=1.21.4",
"unexpected": "5.0.0-beta22",
"unexpected-messy": "2.2.1"
"unexpected": "5.0.0-beta22"
},

@@ -36,0 +35,0 @@ "dependencies": {

@@ -21,3 +21,3 @@ /*global describe, it*/

var headers = new Headers({subject: 'hey there, dude!'});
expect(headers.toString(10), 'to equal', 'Subject:\r\n hey\r\n there,\r\n dude!\r\n');
expect(headers.toString(10), 'to equal', 'Subject: hey\r\n there,\r\n dude!\r\n');
});

@@ -24,0 +24,0 @@

/*global describe, it*/
var unexpected = require('unexpected'),
var expect = require('unexpected'),
Message = require('../lib/Message');
describe('Message', function () {
var expect = unexpected.clone().installPlugin(require('unexpected-messy'));
it('should accept an options object with headers and body', function () {

@@ -235,10 +233,8 @@ var message = new Message({

expect(message, 'to satisfy', {
body: [
new Message('Content-Disposition: form-data; name="recipient"\r\n\r\nandreas@one.com'),
new Message('Content-Disposition: form-data; name="Name "\r\n\r\nThe name'),
new Message('Content-Disposition: form-data; name="email"\r\n\r\nthe@email.com'),
new Message('Content-Disposition: form-data; name="Message "\r\n\r\nThe message')
]
});
expect(message.body, 'to equal', [
new Message(new Buffer('Content-Disposition: form-data; name="recipient"\r\n\r\nandreas@one.com', 'utf-8')),
new Message(new Buffer('Content-Disposition: form-data; name="Name "\r\n\r\nThe name', 'utf-8')),
new Message(new Buffer('Content-Disposition: form-data; name="email"\r\n\r\nthe@email.com', 'utf-8')),
new Message(new Buffer('Content-Disposition: form-data; name="Message "\r\n\r\nThe message', 'utf-8'))
]);
});

@@ -245,0 +241,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc