From fb7701576ec921690fd9c4f30ee471b0a4c2c11b Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 13 Oct 2017 11:44:35 -0700 Subject: [PATCH] Update autosize, which should fix stack overflow error (#1560) * Update to the latest version of autosize.js * gitignore: Restrict 'dist' matches to the root dist folder The global search for 'dist' caused problems when updateing bower components. * A couple minor version updates: ByteBuffer, filesize, intlTel moment-with-localse, ProtoBuf --- .gitignore | 2 +- bower.json | 2 +- components/autosize/dist/autosize.js | 221 +++++++++----- components/bytebuffer/dist/ByteBufferAB.js | 30 +- components/filesize/lib/filesize.js | 2 +- .../intl-tel-input/build/js/intlTelInput.js | 16 +- components/moment/min/moment-with-locales.js | 4 +- components/protobuf/dist/ProtoBuf.js | 7 +- js/components.js | 279 ++++++++++++------ libtextsecure/components.js | 37 ++- 10 files changed, 398 insertions(+), 202 deletions(-) diff --git a/.gitignore b/.gitignore index 50cf2f0b0d22..357b5f23ea4a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ node_modules build/curve25519_compiled.js build/icons/* stylesheets/*.css.map -dist +/dist .DS_Store config/local.json config/local-*.json diff --git a/bower.json b/bower.json index 9f98a540923b..440f55eacdd7 100644 --- a/bower.json +++ b/bower.json @@ -17,7 +17,7 @@ "intl-tel-input": "~4.0.1", "blueimp-load-image": "~1.13.0", "blueimp-canvas-to-blob": "~2.1.1", - "autosize": "~3.0.6", + "autosize": "~4.0.0", "webaudiorecorder": "https://github.com/higuma/web-audio-recorder-js.git", "mp3lameencoder": "https://github.com/higuma/mp3-lame-encoder-js.git", "filesize": "https://github.com/avoidwork/filesize.js.git" diff --git a/components/autosize/dist/autosize.js b/components/autosize/dist/autosize.js index 884c7db41f29..e0a21c76486e 100644 --- a/components/autosize/dist/autosize.js +++ b/components/autosize/dist/autosize.js @@ -1,5 +1,5 @@ /*! - Autosize 3.0.5 + Autosize 4.0.0 license: MIT http://www.jacklmoore.com/autosize */ @@ -18,18 +18,53 @@ })(this, function (exports, module) { 'use strict'; + var map = typeof Map === "function" ? new Map() : (function () { + var keys = []; + var values = []; + + return { + has: function has(key) { + return keys.indexOf(key) > -1; + }, + get: function get(key) { + return values[keys.indexOf(key)]; + }, + set: function set(key, value) { + if (keys.indexOf(key) === -1) { + keys.push(key); + values.push(value); + } + }, + 'delete': function _delete(key) { + var index = keys.indexOf(key); + if (index > -1) { + keys.splice(index, 1); + values.splice(index, 1); + } + } + }; + })(); + + var createEvent = function createEvent(name) { + return new Event(name, { bubbles: true }); + }; + try { + new Event('test'); + } catch (e) { + // IE does not support `new Event()` + createEvent = function (name) { + var evt = document.createEvent('Event'); + evt.initEvent(name, true, false); + return evt; + }; + } + function assign(ta) { - var _ref = arguments[1] === undefined ? {} : arguments[1]; - - var _ref$setOverflowX = _ref.setOverflowX; - var setOverflowX = _ref$setOverflowX === undefined ? true : _ref$setOverflowX; - var _ref$setOverflowY = _ref.setOverflowY; - var setOverflowY = _ref$setOverflowY === undefined ? true : _ref$setOverflowY; - - if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || ta.hasAttribute('data-autosize-on')) return; + if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || map.has(ta)) return; var heightOffset = null; - var overflowY = 'hidden'; + var clientWidth = ta.clientWidth; + var cachedHeight = null; function init() { var style = window.getComputedStyle(ta, null); @@ -45,6 +80,10 @@ } else { heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth); } + // Fix when a textarea is not on document body and heightOffset is Not a Number + if (isNaN(heightOffset)) { + heightOffset = 0; + } update(); } @@ -63,22 +102,31 @@ ta.style.width = width; } - overflowY = value; - - if (setOverflowY) { - ta.style.overflowY = value; - } - - update(); + ta.style.overflowY = value; } - function update() { - var startHeight = ta.style.height; - var htmlTop = document.documentElement.scrollTop; - var bodyTop = document.body.scrollTop; - var originalHeight = ta.style.height; + function getParentOverflows(el) { + var arr = []; - ta.style.height = 'auto'; + while (el && el.parentNode && el.parentNode instanceof Element) { + if (el.parentNode.scrollTop) { + arr.push({ + node: el.parentNode, + scrollTop: el.parentNode.scrollTop + }); + } + el = el.parentNode; + } + + return arr; + } + + function resize() { + var originalHeight = ta.style.height; + var overflows = getParentOverflows(ta); + var docTop = document.documentElement && document.documentElement.scrollTop; // Needed for Mobile IE (ticket #240) + + ta.style.height = ''; var endHeight = ta.scrollHeight + heightOffset; @@ -90,85 +138,118 @@ ta.style.height = endHeight + 'px'; + // used to check if an update is actually necessary on window.resize + clientWidth = ta.clientWidth; + // prevents scroll-position jumping - document.documentElement.scrollTop = htmlTop; - document.body.scrollTop = bodyTop; + overflows.forEach(function (el) { + el.node.scrollTop = el.scrollTop; + }); - var style = window.getComputedStyle(ta, null); - - if (style.height !== ta.style.height) { - if (overflowY !== 'visible') { - changeOverflow('visible'); - return; - } - } else { - if (overflowY !== 'hidden') { - changeOverflow('hidden'); - return; - } - } - - if (startHeight !== ta.style.height) { - var evt = document.createEvent('Event'); - evt.initEvent('autosize:resized', true, false); - ta.dispatchEvent(evt); + if (docTop) { + document.documentElement.scrollTop = docTop; } } + function update() { + resize(); + + var styleHeight = Math.round(parseFloat(ta.style.height)); + var computed = window.getComputedStyle(ta, null); + + // Using offsetHeight as a replacement for computed.height in IE, because IE does not account use of border-box + var actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(computed.height)) : ta.offsetHeight; + + // The actual height not matching the style height (set via the resize method) indicates that + // the max-height has been exceeded, in which case the overflow should be allowed. + if (actualHeight !== styleHeight) { + if (computed.overflowY === 'hidden') { + changeOverflow('scroll'); + resize(); + actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight; + } + } else { + // Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands. + if (computed.overflowY !== 'hidden') { + changeOverflow('hidden'); + resize(); + actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight; + } + } + + if (cachedHeight !== actualHeight) { + cachedHeight = actualHeight; + var evt = createEvent('autosize:resized'); + try { + ta.dispatchEvent(evt); + } catch (err) { + // Firefox will throw an error on dispatchEvent for a detached element + // https://bugzilla.mozilla.org/show_bug.cgi?id=889376 + } + } + } + + var pageResize = function pageResize() { + if (ta.clientWidth !== clientWidth) { + update(); + } + }; + var destroy = (function (style) { - window.removeEventListener('resize', update); - ta.removeEventListener('input', update); - ta.removeEventListener('keyup', update); - ta.removeAttribute('data-autosize-on'); - ta.removeEventListener('autosize:destroy', destroy); + window.removeEventListener('resize', pageResize, false); + ta.removeEventListener('input', update, false); + ta.removeEventListener('keyup', update, false); + ta.removeEventListener('autosize:destroy', destroy, false); + ta.removeEventListener('autosize:update', update, false); Object.keys(style).forEach(function (key) { ta.style[key] = style[key]; }); + + map['delete'](ta); }).bind(ta, { height: ta.style.height, resize: ta.style.resize, overflowY: ta.style.overflowY, overflowX: ta.style.overflowX, - wordWrap: ta.style.wordWrap }); + wordWrap: ta.style.wordWrap + }); - ta.addEventListener('autosize:destroy', destroy); + ta.addEventListener('autosize:destroy', destroy, false); // IE9 does not fire onpropertychange or oninput for deletions, // so binding to onkeyup to catch most of those events. // There is no way that I know of to detect something like 'cut' in IE9. if ('onpropertychange' in ta && 'oninput' in ta) { - ta.addEventListener('keyup', update); + ta.addEventListener('keyup', update, false); } - window.addEventListener('resize', update); - ta.addEventListener('input', update); - ta.addEventListener('autosize:update', update); - ta.setAttribute('data-autosize-on', true); + window.addEventListener('resize', pageResize, false); + ta.addEventListener('input', update, false); + ta.addEventListener('autosize:update', update, false); + ta.style.overflowX = 'hidden'; + ta.style.wordWrap = 'break-word'; - if (setOverflowY) { - ta.style.overflowY = 'hidden'; - } - if (setOverflowX) { - ta.style.overflowX = 'hidden'; - ta.style.wordWrap = 'break-word'; - } + map.set(ta, { + destroy: destroy, + update: update + }); init(); } function destroy(ta) { - if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return; - var evt = document.createEvent('Event'); - evt.initEvent('autosize:destroy', true, false); - ta.dispatchEvent(evt); + var methods = map.get(ta); + if (methods) { + methods.destroy(); + } } function update(ta) { - if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return; - var evt = document.createEvent('Event'); - evt.initEvent('autosize:update', true, false); - ta.dispatchEvent(evt); + var methods = map.get(ta); + if (methods) { + methods.update(); + } } var autosize = null; diff --git a/components/bytebuffer/dist/ByteBufferAB.js b/components/bytebuffer/dist/ByteBufferAB.js index 7168997a2de9..df5e118480d3 100644 --- a/components/bytebuffer/dist/ByteBufferAB.js +++ b/components/bytebuffer/dist/ByteBufferAB.js @@ -16,7 +16,8 @@ /** * @license ByteBuffer.js (c) 2013-2014 Daniel Wirtz - * This version of ByteBuffer.js uses an ArrayBuffer (AB) as its backing buffer and is compatible with modern browsers. + * This version of ByteBuffer.js uses an ArrayBuffer as its backing buffer which is accessed through a DataView and is + * compatible with modern browsers. * Released under the Apache License, Version 2.0 * see: https://github.com/dcodeIO/ByteBuffer.js for details */ // @@ -116,7 +117,7 @@ * @const * @expose */ - ByteBuffer.VERSION = "3.5.4"; + ByteBuffer.VERSION = "3.5.5"; /** * Little endian constant that can be used instead of its boolean value. Evaluates to `true`. @@ -752,6 +753,8 @@ if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -762,6 +765,8 @@ } if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); offset += 8; var capacity6 = this.buffer.byteLength; if (offset > capacity6) @@ -831,6 +836,8 @@ if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -841,6 +848,8 @@ } if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); offset += 8; var capacity7 = this.buffer.byteLength; if (offset > capacity7) @@ -1237,6 +1246,8 @@ ByteBuffer.calculateVarint64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); // ref: src/google/protobuf/io/coded_stream.cc var part0 = value.toInt() >>> 0, part1 = value.shiftRightUnsigned(28).toInt() >>> 0, @@ -1266,6 +1277,8 @@ ByteBuffer.zigZagEncode64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); // ref: src/google/protobuf/wire_format_lite.h return value.shiftLeft(1).xor(value.shiftRight(63)).toUnsigned(); @@ -1280,6 +1293,8 @@ ByteBuffer.zigZagDecode64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); // ref: src/google/protobuf/wire_format_lite.h return value.shiftRightUnsigned(1).xor(value.and(Long.ONE).toSigned().negate()).toSigned(); @@ -1299,6 +1314,8 @@ if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -1309,6 +1326,8 @@ } if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); var size = ByteBuffer.calculateVarint64(value), part0 = value.toInt() >>> 0, @@ -1449,7 +1468,6 @@ if (offset < 0 || offset + 0 > this.buffer.byteLength) throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); } - var start = offset; // UTF8 strings do not contain zero bytes in between except for the zero character, so: k = utfx.calculateUTF16asUTF8(stringSource(str))[1]; offset += k+1; @@ -1462,7 +1480,7 @@ }.bind(this)); this.view.setUint8(offset++, 0); if (relative) { - this.offset = offset - start; + this.offset = offset; return this; } return k; @@ -1901,8 +1919,8 @@ }; /** - * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents behind the specified - * offset up to the length of this ByteBuffer's data. + * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents at and after the + specified offset up to the length of this ByteBuffer's data. * @param {!ByteBuffer} target Target ByteBuffer * @param {number=} offset Offset to append to. Will use and increase {@link ByteBuffer#offset} by the number of bytes * read if omitted. diff --git a/components/filesize/lib/filesize.js b/components/filesize/lib/filesize.js index e325eee35059..2d2421ad3d16 100644 --- a/components/filesize/lib/filesize.js +++ b/components/filesize/lib/filesize.js @@ -5,7 +5,7 @@ * * @copyright 2017 Jason Mulligan * @license BSD-3-Clause - * @version 3.5.9 + * @version 3.5.10 */ (function (global) { var b = /^(b|B)$/, diff --git a/components/intl-tel-input/build/js/intlTelInput.js b/components/intl-tel-input/build/js/intlTelInput.js index 5b0ed11e2f8c..c86003149ddb 100644 --- a/components/intl-tel-input/build/js/intlTelInput.js +++ b/components/intl-tel-input/build/js/intlTelInput.js @@ -1,5 +1,5 @@ /* -International Telephone Input v4.0.1 +International Telephone Input v4.0.2 https://github.com/Bluefieldscom/intl-tel-input.git */ // wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPlugin.js @@ -651,14 +651,7 @@ https://github.com/Bluefieldscom/intl-tel-input.git var dialCode = this._getDialCode(number); if (dialCode) { // check if one of the matching countries is already selected - var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = false; - if (this.selectedCountryData) { - for (var i = 0; i < countryCodes.length; i++) { - if (countryCodes[i] == this.selectedCountryData.iso2) { - alreadySelected = true; - } - } - } + var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = this.selectedCountryData && $.inArray(this.selectedCountryData.iso2, countryCodes) != -1; // if a matching country is not already selected (or this is an unknown NANP area code): choose the first in the list if (!alreadySelected || this._isUnknownNanp(number, dialCode)) { // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index @@ -706,9 +699,8 @@ https://github.com/Bluefieldscom/intl-tel-input.git // and the input's placeholder this._updatePlaceholder(); // update the active list item - var listItem = this.countryListItems.children(".iti-flag." + countryCode).first().parent(); this.countryListItems.removeClass("active"); - listItem.addClass("active"); + this.countryListItems.children(".iti-flag." + countryCode).first().parent().addClass("active"); }, // update the input placeholder to an example number from the currently selected country _updatePlaceholder: function() { @@ -1004,4 +996,4 @@ JSON.stringify(result); areaCodes: c[4] || null }; } -}); +}); \ No newline at end of file diff --git a/components/moment/min/moment-with-locales.js b/components/moment/min/moment-with-locales.js index 1f4eb8108357..80ac6112f2f4 100644 --- a/components/moment/min/moment-with-locales.js +++ b/components/moment/min/moment-with-locales.js @@ -1,5 +1,5 @@ //! moment.js -//! version : 2.14.1 +//! version : 2.14.2 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors //! license : MIT //! momentjs.com @@ -4158,7 +4158,7 @@ ; - utils_hooks__hooks.version = '2.14.1'; + utils_hooks__hooks.version = '2.14.2'; setHookCallback(local__createLocal); diff --git a/components/protobuf/dist/ProtoBuf.js b/components/protobuf/dist/ProtoBuf.js index 3ce17404965c..0e12340a7ffb 100644 --- a/components/protobuf/dist/ProtoBuf.js +++ b/components/protobuf/dist/ProtoBuf.js @@ -38,7 +38,7 @@ * @const * @expose */ - ProtoBuf.VERSION = "3.8.0"; + ProtoBuf.VERSION = "3.8.2"; /** * Wire types. @@ -402,7 +402,7 @@ ID: /^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, NEGID: /^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, WHITESPACE: /\s/, - STRING: /['"]([^'"\\]*(\\.[^"\\]*)*)['"]/g, + STRING: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g, BOOL: /^(?:true|false)$/i }; @@ -488,7 +488,7 @@ Lang.STRING.lastIndex = this.index-1; // Include the open quote var match; if ((match = Lang.STRING.exec(this.source)) !== null) { - var s = match[1]; + var s = typeof match[1] !== 'undefined' ? match[1] : match[2]; this.index = Lang.STRING.lastIndex; this.stack.push(this.stringEndsWith); return s; @@ -4285,7 +4285,6 @@ json = JSON.parse(json); builder["import"](json, filename); builder.resolveAll(); - builder.build(); return builder; }; diff --git a/js/components.js b/js/components.js index bfbb7b7bf55a..ac84ec58ce3a 100644 --- a/js/components.js +++ b/js/components.js @@ -10165,7 +10165,8 @@ return jQuery; /** * @license ByteBuffer.js (c) 2013-2014 Daniel Wirtz - * This version of ByteBuffer.js uses an ArrayBuffer (AB) as its backing buffer and is compatible with modern browsers. + * This version of ByteBuffer.js uses an ArrayBuffer as its backing buffer which is accessed through a DataView and is + * compatible with modern browsers. * Released under the Apache License, Version 2.0 * see: https://github.com/dcodeIO/ByteBuffer.js for details */ // @@ -10265,7 +10266,7 @@ return jQuery; * @const * @expose */ - ByteBuffer.VERSION = "3.5.4"; + ByteBuffer.VERSION = "3.5.5"; /** * Little endian constant that can be used instead of its boolean value. Evaluates to `true`. @@ -10901,6 +10902,8 @@ return jQuery; if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -10911,6 +10914,8 @@ return jQuery; } if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); offset += 8; var capacity6 = this.buffer.byteLength; if (offset > capacity6) @@ -10980,6 +10985,8 @@ return jQuery; if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -10990,6 +10997,8 @@ return jQuery; } if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); offset += 8; var capacity7 = this.buffer.byteLength; if (offset > capacity7) @@ -11386,6 +11395,8 @@ return jQuery; ByteBuffer.calculateVarint64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); // ref: src/google/protobuf/io/coded_stream.cc var part0 = value.toInt() >>> 0, part1 = value.shiftRightUnsigned(28).toInt() >>> 0, @@ -11415,6 +11426,8 @@ return jQuery; ByteBuffer.zigZagEncode64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); // ref: src/google/protobuf/wire_format_lite.h return value.shiftLeft(1).xor(value.shiftRight(63)).toUnsigned(); @@ -11429,6 +11442,8 @@ return jQuery; ByteBuffer.zigZagDecode64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); // ref: src/google/protobuf/wire_format_lite.h return value.shiftRightUnsigned(1).xor(value.and(Long.ONE).toSigned().negate()).toSigned(); @@ -11448,6 +11463,8 @@ return jQuery; if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -11458,6 +11475,8 @@ return jQuery; } if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); var size = ByteBuffer.calculateVarint64(value), part0 = value.toInt() >>> 0, @@ -11598,7 +11617,6 @@ return jQuery; if (offset < 0 || offset + 0 > this.buffer.byteLength) throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); } - var start = offset; // UTF8 strings do not contain zero bytes in between except for the zero character, so: k = utfx.calculateUTF16asUTF8(stringSource(str))[1]; offset += k+1; @@ -11611,7 +11629,7 @@ return jQuery; }.bind(this)); this.view.setUint8(offset++, 0); if (relative) { - this.offset = offset - start; + this.offset = offset; return this; } return k; @@ -12050,8 +12068,8 @@ return jQuery; }; /** - * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents behind the specified - * offset up to the length of this ByteBuffer's data. + * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents at and after the + specified offset up to the length of this ByteBuffer's data. * @param {!ByteBuffer} target Target ByteBuffer * @param {number=} offset Offset to append to. Will use and increase {@link ByteBuffer#offset} by the number of bytes * read if omitted. @@ -13463,7 +13481,7 @@ return jQuery; * @const * @expose */ - ProtoBuf.VERSION = "3.8.0"; + ProtoBuf.VERSION = "3.8.2"; /** * Wire types. @@ -13827,7 +13845,7 @@ return jQuery; ID: /^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, NEGID: /^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, WHITESPACE: /\s/, - STRING: /['"]([^'"\\]*(\\.[^"\\]*)*)['"]/g, + STRING: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g, BOOL: /^(?:true|false)$/i }; @@ -13913,7 +13931,7 @@ return jQuery; Lang.STRING.lastIndex = this.index-1; // Include the open quote var match; if ((match = Lang.STRING.exec(this.source)) !== null) { - var s = match[1]; + var s = typeof match[1] !== 'undefined' ? match[1] : match[2]; this.index = Lang.STRING.lastIndex; this.stack.push(this.stringEndsWith); return s; @@ -17710,7 +17728,6 @@ return jQuery; json = JSON.parse(json); builder["import"](json, filename); builder.resolveAll(); - builder.build(); return builder; }; @@ -23445,7 +23462,7 @@ goog.exportSymbol("libphonenumber.isValidNumber",libphonenumber.isValidNumber);g goog.exportSymbol("libphonenumber.PhoneNumberFormat.NATIONAL",libphonenumber.PhoneNumberFormat.NATIONAL);goog.exportSymbol("libphonenumber.PhoneNumberFormat.RFC3966",libphonenumber.PhoneNumberFormat.RFC3966);goog.exportSymbol("libphonenumber.format",libphonenumber.format);})(); //! moment.js -//! version : 2.14.1 +//! version : 2.14.2 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors //! license : MIT //! momentjs.com @@ -27604,7 +27621,7 @@ goog.exportSymbol("libphonenumber.PhoneNumberFormat.NATIONAL",libphonenumber.Pho ; - utils_hooks__hooks.version = '2.14.1'; + utils_hooks__hooks.version = '2.14.2'; setHookCallback(local__createLocal); @@ -35399,7 +35416,7 @@ goog.exportSymbol("libphonenumber.PhoneNumberFormat.NATIONAL",libphonenumber.Pho })); /* -International Telephone Input v4.0.1 +International Telephone Input v4.0.2 https://github.com/Bluefieldscom/intl-tel-input.git */ // wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPlugin.js @@ -36051,14 +36068,7 @@ https://github.com/Bluefieldscom/intl-tel-input.git var dialCode = this._getDialCode(number); if (dialCode) { // check if one of the matching countries is already selected - var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = false; - if (this.selectedCountryData) { - for (var i = 0; i < countryCodes.length; i++) { - if (countryCodes[i] == this.selectedCountryData.iso2) { - alreadySelected = true; - } - } - } + var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = this.selectedCountryData && $.inArray(this.selectedCountryData.iso2, countryCodes) != -1; // if a matching country is not already selected (or this is an unknown NANP area code): choose the first in the list if (!alreadySelected || this._isUnknownNanp(number, dialCode)) { // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index @@ -36106,9 +36116,8 @@ https://github.com/Bluefieldscom/intl-tel-input.git // and the input's placeholder this._updatePlaceholder(); // update the active list item - var listItem = this.countryListItems.children(".iti-flag." + countryCode).first().parent(); this.countryListItems.removeClass("active"); - listItem.addClass("active"); + this.countryListItems.children(".iti-flag." + countryCode).first().parent().addClass("active"); }, // update the input placeholder to an example number from the currently selected country _updatePlaceholder: function() { @@ -36405,7 +36414,6 @@ JSON.stringify(result); }; } }); - /* * JavaScript Load Image 1.10.0 * https://github.com/blueimp/JavaScript-Load-Image @@ -36805,7 +36813,7 @@ JSON.stringify(result); }(this)); /*! - Autosize 3.0.5 + Autosize 4.0.0 license: MIT http://www.jacklmoore.com/autosize */ @@ -36824,18 +36832,53 @@ JSON.stringify(result); })(this, function (exports, module) { 'use strict'; + var map = typeof Map === "function" ? new Map() : (function () { + var keys = []; + var values = []; + + return { + has: function has(key) { + return keys.indexOf(key) > -1; + }, + get: function get(key) { + return values[keys.indexOf(key)]; + }, + set: function set(key, value) { + if (keys.indexOf(key) === -1) { + keys.push(key); + values.push(value); + } + }, + 'delete': function _delete(key) { + var index = keys.indexOf(key); + if (index > -1) { + keys.splice(index, 1); + values.splice(index, 1); + } + } + }; + })(); + + var createEvent = function createEvent(name) { + return new Event(name, { bubbles: true }); + }; + try { + new Event('test'); + } catch (e) { + // IE does not support `new Event()` + createEvent = function (name) { + var evt = document.createEvent('Event'); + evt.initEvent(name, true, false); + return evt; + }; + } + function assign(ta) { - var _ref = arguments[1] === undefined ? {} : arguments[1]; - - var _ref$setOverflowX = _ref.setOverflowX; - var setOverflowX = _ref$setOverflowX === undefined ? true : _ref$setOverflowX; - var _ref$setOverflowY = _ref.setOverflowY; - var setOverflowY = _ref$setOverflowY === undefined ? true : _ref$setOverflowY; - - if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || ta.hasAttribute('data-autosize-on')) return; + if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || map.has(ta)) return; var heightOffset = null; - var overflowY = 'hidden'; + var clientWidth = ta.clientWidth; + var cachedHeight = null; function init() { var style = window.getComputedStyle(ta, null); @@ -36851,6 +36894,10 @@ JSON.stringify(result); } else { heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth); } + // Fix when a textarea is not on document body and heightOffset is Not a Number + if (isNaN(heightOffset)) { + heightOffset = 0; + } update(); } @@ -36869,22 +36916,31 @@ JSON.stringify(result); ta.style.width = width; } - overflowY = value; - - if (setOverflowY) { - ta.style.overflowY = value; - } - - update(); + ta.style.overflowY = value; } - function update() { - var startHeight = ta.style.height; - var htmlTop = document.documentElement.scrollTop; - var bodyTop = document.body.scrollTop; - var originalHeight = ta.style.height; + function getParentOverflows(el) { + var arr = []; - ta.style.height = 'auto'; + while (el && el.parentNode && el.parentNode instanceof Element) { + if (el.parentNode.scrollTop) { + arr.push({ + node: el.parentNode, + scrollTop: el.parentNode.scrollTop + }); + } + el = el.parentNode; + } + + return arr; + } + + function resize() { + var originalHeight = ta.style.height; + var overflows = getParentOverflows(ta); + var docTop = document.documentElement && document.documentElement.scrollTop; // Needed for Mobile IE (ticket #240) + + ta.style.height = ''; var endHeight = ta.scrollHeight + heightOffset; @@ -36896,85 +36952,118 @@ JSON.stringify(result); ta.style.height = endHeight + 'px'; + // used to check if an update is actually necessary on window.resize + clientWidth = ta.clientWidth; + // prevents scroll-position jumping - document.documentElement.scrollTop = htmlTop; - document.body.scrollTop = bodyTop; + overflows.forEach(function (el) { + el.node.scrollTop = el.scrollTop; + }); - var style = window.getComputedStyle(ta, null); - - if (style.height !== ta.style.height) { - if (overflowY !== 'visible') { - changeOverflow('visible'); - return; - } - } else { - if (overflowY !== 'hidden') { - changeOverflow('hidden'); - return; - } - } - - if (startHeight !== ta.style.height) { - var evt = document.createEvent('Event'); - evt.initEvent('autosize:resized', true, false); - ta.dispatchEvent(evt); + if (docTop) { + document.documentElement.scrollTop = docTop; } } + function update() { + resize(); + + var styleHeight = Math.round(parseFloat(ta.style.height)); + var computed = window.getComputedStyle(ta, null); + + // Using offsetHeight as a replacement for computed.height in IE, because IE does not account use of border-box + var actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(computed.height)) : ta.offsetHeight; + + // The actual height not matching the style height (set via the resize method) indicates that + // the max-height has been exceeded, in which case the overflow should be allowed. + if (actualHeight !== styleHeight) { + if (computed.overflowY === 'hidden') { + changeOverflow('scroll'); + resize(); + actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight; + } + } else { + // Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands. + if (computed.overflowY !== 'hidden') { + changeOverflow('hidden'); + resize(); + actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight; + } + } + + if (cachedHeight !== actualHeight) { + cachedHeight = actualHeight; + var evt = createEvent('autosize:resized'); + try { + ta.dispatchEvent(evt); + } catch (err) { + // Firefox will throw an error on dispatchEvent for a detached element + // https://bugzilla.mozilla.org/show_bug.cgi?id=889376 + } + } + } + + var pageResize = function pageResize() { + if (ta.clientWidth !== clientWidth) { + update(); + } + }; + var destroy = (function (style) { - window.removeEventListener('resize', update); - ta.removeEventListener('input', update); - ta.removeEventListener('keyup', update); - ta.removeAttribute('data-autosize-on'); - ta.removeEventListener('autosize:destroy', destroy); + window.removeEventListener('resize', pageResize, false); + ta.removeEventListener('input', update, false); + ta.removeEventListener('keyup', update, false); + ta.removeEventListener('autosize:destroy', destroy, false); + ta.removeEventListener('autosize:update', update, false); Object.keys(style).forEach(function (key) { ta.style[key] = style[key]; }); + + map['delete'](ta); }).bind(ta, { height: ta.style.height, resize: ta.style.resize, overflowY: ta.style.overflowY, overflowX: ta.style.overflowX, - wordWrap: ta.style.wordWrap }); + wordWrap: ta.style.wordWrap + }); - ta.addEventListener('autosize:destroy', destroy); + ta.addEventListener('autosize:destroy', destroy, false); // IE9 does not fire onpropertychange or oninput for deletions, // so binding to onkeyup to catch most of those events. // There is no way that I know of to detect something like 'cut' in IE9. if ('onpropertychange' in ta && 'oninput' in ta) { - ta.addEventListener('keyup', update); + ta.addEventListener('keyup', update, false); } - window.addEventListener('resize', update); - ta.addEventListener('input', update); - ta.addEventListener('autosize:update', update); - ta.setAttribute('data-autosize-on', true); + window.addEventListener('resize', pageResize, false); + ta.addEventListener('input', update, false); + ta.addEventListener('autosize:update', update, false); + ta.style.overflowX = 'hidden'; + ta.style.wordWrap = 'break-word'; - if (setOverflowY) { - ta.style.overflowY = 'hidden'; - } - if (setOverflowX) { - ta.style.overflowX = 'hidden'; - ta.style.wordWrap = 'break-word'; - } + map.set(ta, { + destroy: destroy, + update: update + }); init(); } function destroy(ta) { - if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return; - var evt = document.createEvent('Event'); - evt.initEvent('autosize:destroy', true, false); - ta.dispatchEvent(evt); + var methods = map.get(ta); + if (methods) { + methods.destroy(); + } } function update(ta) { - if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return; - var evt = document.createEvent('Event'); - evt.initEvent('autosize:update', true, false); - ta.dispatchEvent(evt); + var methods = map.get(ta); + if (methods) { + methods.update(); + } } var autosize = null; @@ -37022,7 +37111,7 @@ JSON.stringify(result); * * @copyright 2017 Jason Mulligan * @license BSD-3-Clause - * @version 3.5.9 + * @version 3.5.10 */ (function (global) { var b = /^(b|B)$/, diff --git a/libtextsecure/components.js b/libtextsecure/components.js index 98d9e43145ba..ef059e592904 100644 --- a/libtextsecure/components.js +++ b/libtextsecure/components.js @@ -959,7 +959,8 @@ /** * @license ByteBuffer.js (c) 2013-2014 Daniel Wirtz - * This version of ByteBuffer.js uses an ArrayBuffer (AB) as its backing buffer and is compatible with modern browsers. + * This version of ByteBuffer.js uses an ArrayBuffer as its backing buffer which is accessed through a DataView and is + * compatible with modern browsers. * Released under the Apache License, Version 2.0 * see: https://github.com/dcodeIO/ByteBuffer.js for details */ // @@ -1059,7 +1060,7 @@ * @const * @expose */ - ByteBuffer.VERSION = "3.5.4"; + ByteBuffer.VERSION = "3.5.5"; /** * Little endian constant that can be used instead of its boolean value. Evaluates to `true`. @@ -1695,6 +1696,8 @@ if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -1705,6 +1708,8 @@ } if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); offset += 8; var capacity6 = this.buffer.byteLength; if (offset > capacity6) @@ -1774,6 +1779,8 @@ if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -1784,6 +1791,8 @@ } if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); offset += 8; var capacity7 = this.buffer.byteLength; if (offset > capacity7) @@ -2180,6 +2189,8 @@ ByteBuffer.calculateVarint64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); // ref: src/google/protobuf/io/coded_stream.cc var part0 = value.toInt() >>> 0, part1 = value.shiftRightUnsigned(28).toInt() >>> 0, @@ -2209,6 +2220,8 @@ ByteBuffer.zigZagEncode64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); // ref: src/google/protobuf/wire_format_lite.h return value.shiftLeft(1).xor(value.shiftRight(63)).toUnsigned(); @@ -2223,6 +2236,8 @@ ByteBuffer.zigZagDecode64 = function(value) { if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); // ref: src/google/protobuf/wire_format_lite.h return value.shiftRightUnsigned(1).xor(value.and(Long.ONE).toSigned().negate()).toSigned(); @@ -2242,6 +2257,8 @@ if (!this.noAssert) { if (typeof value === 'number') value = Long.fromNumber(value); + else if (typeof value === 'string') + value = Long.fromString(value); else if (!(value && value instanceof Long)) throw TypeError("Illegal value: "+value+" (not an integer or Long)"); if (typeof offset !== 'number' || offset % 1 !== 0) @@ -2252,6 +2269,8 @@ } if (typeof value === 'number') value = Long.fromNumber(value, false); + else if (typeof value === 'string') + value = Long.fromString(value, false); else if (value.unsigned !== false) value = value.toSigned(); var size = ByteBuffer.calculateVarint64(value), part0 = value.toInt() >>> 0, @@ -2392,7 +2411,6 @@ if (offset < 0 || offset + 0 > this.buffer.byteLength) throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength); } - var start = offset; // UTF8 strings do not contain zero bytes in between except for the zero character, so: k = utfx.calculateUTF16asUTF8(stringSource(str))[1]; offset += k+1; @@ -2405,7 +2423,7 @@ }.bind(this)); this.view.setUint8(offset++, 0); if (relative) { - this.offset = offset - start; + this.offset = offset; return this; } return k; @@ -2844,8 +2862,8 @@ }; /** - * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents behind the specified - * offset up to the length of this ByteBuffer's data. + * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents at and after the + specified offset up to the length of this ByteBuffer's data. * @param {!ByteBuffer} target Target ByteBuffer * @param {number=} offset Offset to append to. Will use and increase {@link ByteBuffer#offset} by the number of bytes * read if omitted. @@ -4257,7 +4275,7 @@ * @const * @expose */ - ProtoBuf.VERSION = "3.8.0"; + ProtoBuf.VERSION = "3.8.2"; /** * Wire types. @@ -4621,7 +4639,7 @@ ID: /^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, NEGID: /^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, WHITESPACE: /\s/, - STRING: /['"]([^'"\\]*(\\.[^"\\]*)*)['"]/g, + STRING: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g, BOOL: /^(?:true|false)$/i }; @@ -4707,7 +4725,7 @@ Lang.STRING.lastIndex = this.index-1; // Include the open quote var match; if ((match = Lang.STRING.exec(this.source)) !== null) { - var s = match[1]; + var s = typeof match[1] !== 'undefined' ? match[1] : match[2]; this.index = Lang.STRING.lastIndex; this.stack.push(this.stringEndsWith); return s; @@ -8504,7 +8522,6 @@ json = JSON.parse(json); builder["import"](json, filename); builder.resolveAll(); - builder.build(); return builder; };