Bug 1401528 - check of existence of softMargin and hardMargin in options to HeaderEmitter. r=jcranmer
--- a/mailnews/mime/jsmime/jsmime.js
+++ b/mailnews/mime/jsmime/jsmime.js
@@ -2522,20 +2522,22 @@ var mimeutils = require('./mimeutils');
// Get the default structured encoders and add them to the map
var structuredHeaders = require('./structuredHeaders');
var encoders = new Map();
var preferredSpellings = structuredHeaders.spellings;
for (let [header, encoder] of structuredHeaders.encoders) {
addStructuredEncoder(header, encoder);
}
-/// Clamp a value in the range [min, max], defaulting to def if it is undefined.
-function clamp(value, min, max, def) {
- if (value === undefined)
+/// Clamp a value in the range [min, max], defaulting to def
+/// if the object[property] does not contain the value.
+function clamp(object, property, min, max, def) {
+ if (!(property in object))
return def;
+ let value = object[property];
if (value < min)
return min;
if (value > max)
return max;
return value;
}
/**
@@ -2598,18 +2600,18 @@ function HeaderEmitter(handler, options)
// Our bounds for soft and margins are not completely arbitrary. The minimum
// amount we need to encode is 20 characters, which can encode a single
// non-BMP character with RFC 2047. The value of 30 is chosen to give some
// breathing room for delimiters or other unbreakable characters. The maximum
// length is 998 octets, per RFC 5322; soft margins are slightly lower to
// allow for breathing room as well. The default of 78 for the soft margin is
// recommended by RFC 5322; the default of 332 for the hard margin ensures
// that UTF-8 encoding the output never violates the 998 octet limit.
- this._softMargin = clamp(options.softMargin, 30, 900, 78);
- this._hardMargin = clamp(options.hardMargin, this._softMargin, 998, 332);
+ this._softMargin = clamp(options, "softMargin", 30, 900, 78);
+ this._hardMargin = clamp(options, "hardMargin", this._softMargin, 998, 332);
/**
* The index of the last preferred breakable position in the current line.
*
* @type Integer
* @private
*/
this._preferredBreakpoint = 0;