diff options
-rw-r--r-- | node_modules/JSONStream/.travis.yml | 1 | ||||
-rwxr-xr-x | node_modules/JSONStream/index.js | 12 | ||||
-rw-r--r-- | node_modules/JSONStream/node_modules/jsonparse/jsonparse.js | 101 | ||||
-rw-r--r-- | node_modules/JSONStream/node_modules/jsonparse/package.json | 23 | ||||
-rw-r--r-- | node_modules/JSONStream/node_modules/jsonparse/test/big-token.js | 24 | ||||
-rw-r--r-- | node_modules/JSONStream/package.json | 46 | ||||
-rw-r--r-- | node_modules/JSONStream/test/header_footer.js | 1 | ||||
-rw-r--r-- | node_modules/JSONStream/test/keys.js | 2 | ||||
-rw-r--r-- | npm-shrinkwrap.json | 10 | ||||
-rw-r--r-- | package.json | 2 |
10 files changed, 156 insertions, 66 deletions
diff --git a/node_modules/JSONStream/.travis.yml b/node_modules/JSONStream/.travis.yml index 5743d7073..5f30bb5bd 100644 --- a/node_modules/JSONStream/.travis.yml +++ b/node_modules/JSONStream/.travis.yml @@ -3,5 +3,6 @@ node_js: - 4 - 5 - 6 +sudo: false diff --git a/node_modules/JSONStream/index.js b/node_modules/JSONStream/index.js index c164100d9..6d68a19ae 100755 --- a/node_modules/JSONStream/index.js +++ b/node_modules/JSONStream/index.js @@ -94,6 +94,12 @@ exports.parse = function (path, map) { } } + + // emit header + if (header) { + stream.emit('header', header); + header = false; + } if (j !== this.stack.length) return count ++ @@ -115,12 +121,6 @@ exports.parse = function (path, map) { for(var k in this.stack) if (!Object.isFrozen(this.stack[k])) this.stack[k].value = null - - // emit header - if (header) { - stream.emit('header', header); - header = false; - } } parser._onToken = parser.onToken; diff --git a/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js b/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js index 70d9bd04c..26752d4a1 100644 --- a/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js +++ b/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js @@ -40,13 +40,24 @@ var KEY = C.KEY = 0x72; // Parser Modes var OBJECT = C.OBJECT = 0x81; var ARRAY = C.ARRAY = 0x82; +// Character constants +var BACK_SLASH = "\\".charCodeAt(0); +var FORWARD_SLASH = "\/".charCodeAt(0); +var BACKSPACE = "\b".charCodeAt(0); +var FORM_FEED = "\f".charCodeAt(0); +var NEWLINE = "\n".charCodeAt(0); +var CARRIAGE_RETURN = "\r".charCodeAt(0); +var TAB = "\t".charCodeAt(0); +var STRING_BUFFER_SIZE = 64 * 1024; function Parser() { this.tState = START; this.value = undefined; this.string = undefined; // string data + this.stringBuffer = Buffer.alloc ? Buffer.alloc(STRING_BUFFER_SIZE) : new Buffer(STRING_BUFFER_SIZE); + this.stringBufferOffset = 0; this.unicode = undefined; // unicode escapes this.key = undefined; @@ -77,6 +88,41 @@ proto.charError = function (buffer, i) { this.tState = STOP; this.onError(new Error("Unexpected " + JSON.stringify(String.fromCharCode(buffer[i])) + " at position " + i + " in state " + Parser.toknam(this.tState))); }; +proto.appendStringChar = function (char) { + if (this.stringBufferOffset >= STRING_BUFFER_SIZE) { + this.string += this.stringBuffer.toString('utf8'); + this.stringBufferOffset = 0; + } + + this.stringBuffer[this.stringBufferOffset++] = char; +}; +proto.appendStringBuf = function (buf, start, end) { + var size = buf.length; + if (typeof start === 'number') { + if (typeof end === 'number') { + if (end < 0) { + // adding a negative end decreeses the size + size = buf.length - start + end; + } else { + size = end - start; + } + } else { + size = buf.length - start; + } + } + + if (size < 0) { + size = 0; + } + + if (this.stringBufferOffset + size > STRING_BUFFER_SIZE) { + this.string += this.stringBuffer.toString('utf8', 0, this.stringBufferOffset); + this.stringBufferOffset = 0; + } + + buf.copy(this.stringBuffer, this.stringBufferOffset, start, end); + this.stringBufferOffset += size; +}; proto.write = function (buffer) { if (typeof buffer === "string") buffer = new Buffer(buffer); var n; @@ -93,7 +139,10 @@ proto.write = function (buffer) { }else if(n === 0x74){ this.tState = TRUE1; // t }else if(n === 0x66){ this.tState = FALSE1; // f }else if(n === 0x6e){ this.tState = NULL1; // n - }else if(n === 0x22){ this.string = ""; this.tState = STRING1; // " + }else if(n === 0x22){ // " + this.string = ""; + this.stringBufferOffset = 0; + this.tState = STRING1; }else if(n === 0x2d){ this.string = "-"; this.tState = NUMBER1; // - }else{ if (n >= 0x30 && n < 0x40) { // 1-9 @@ -112,7 +161,8 @@ proto.write = function (buffer) { for (var j = 0; j < this.bytes_remaining; j++) { this.temp_buffs[this.bytes_in_sequence][this.bytes_in_sequence - this.bytes_remaining + j] = buffer[j]; } - this.string += this.temp_buffs[this.bytes_in_sequence].toString(); + + this.appendStringBuf(this.temp_buffs[this.bytes_in_sequence]); this.bytes_in_sequence = this.bytes_remaining = 0; i = i + j - 1; } else if (this.bytes_remaining === 0 && n >= 128) { // else if no remainder bytes carried over, parse multi byte (>=128) chars one at a time @@ -129,28 +179,37 @@ proto.write = function (buffer) { this.bytes_remaining = (i + this.bytes_in_sequence) - buffer.length; i = buffer.length - 1; } else { - this.string += buffer.slice(i, (i + this.bytes_in_sequence)).toString(); + this.appendStringBuf(buffer, i, i + this.bytes_in_sequence); i = i + this.bytes_in_sequence - 1; } - } else if (n === 0x22) { this.tState = START; this.onToken(STRING, this.string); this.offset += Buffer.byteLength(this.string, 'utf8') + 1; this.string = undefined; } - else if (n === 0x5c) { this.tState = STRING2; } - else if (n >= 0x20) { this.string += String.fromCharCode(n); } + } else if (n === 0x22) { + this.tState = START; + this.string += this.stringBuffer.toString('utf8', 0, this.stringBufferOffset); + this.stringBufferOffset = 0; + this.onToken(STRING, this.string); + this.offset += Buffer.byteLength(this.string, 'utf8') + 1; + this.string = undefined; + } + else if (n === 0x5c) { + this.tState = STRING2; + } + else if (n >= 0x20) { this.appendStringChar(n); } else { return this.charError(buffer, i); } }else if (this.tState === STRING2){ // After backslash n = buffer[i]; - if(n === 0x22){ this.string += "\""; this.tState = STRING1; - }else if(n === 0x5c){ this.string += "\\"; this.tState = STRING1; - }else if(n === 0x2f){ this.string += "\/"; this.tState = STRING1; - }else if(n === 0x62){ this.string += "\b"; this.tState = STRING1; - }else if(n === 0x66){ this.string += "\f"; this.tState = STRING1; - }else if(n === 0x6e){ this.string += "\n"; this.tState = STRING1; - }else if(n === 0x72){ this.string += "\r"; this.tState = STRING1; - }else if(n === 0x74){ this.string += "\t"; this.tState = STRING1; + if(n === 0x22){ this.appendStringChar(n); this.tState = STRING1; + }else if(n === 0x5c){ this.appendStringChar(BACK_SLASH); this.tState = STRING1; + }else if(n === 0x2f){ this.appendStringChar(FORWARD_SLASH); this.tState = STRING1; + }else if(n === 0x62){ this.appendStringChar(BACKSPACE); this.tState = STRING1; + }else if(n === 0x66){ this.appendStringChar(FORM_FEED); this.tState = STRING1; + }else if(n === 0x6e){ this.appendStringChar(NEWLINE); this.tState = STRING1; + }else if(n === 0x72){ this.appendStringChar(CARRIAGE_RETURN); this.tState = STRING1; + }else if(n === 0x74){ this.appendStringChar(TAB); this.tState = STRING1; }else if(n === 0x75){ this.unicode = ""; this.tState = STRING3; - }else{ - return this.charError(buffer, i); + }else{ + return this.charError(buffer, i); } }else if (this.tState === STRING3 || this.tState === STRING4 || this.tState === STRING5 || this.tState === STRING6){ // unicode hex codes n = buffer[i]; @@ -158,9 +217,9 @@ proto.write = function (buffer) { if ((n >= 0x30 && n < 0x40) || (n > 0x40 && n <= 0x46) || (n > 0x60 && n <= 0x66)) { this.unicode += String.fromCharCode(n); if (this.tState++ === STRING6) { - this.string += String.fromCharCode(parseInt(this.unicode, 16)); + this.appendStringBuf(Buffer(String.fromCharCode(parseInt(this.unicode, 16)))); this.unicode = undefined; - this.tState = STRING1; + this.tState = STRING1; } } else { return this.charError(buffer, i); @@ -266,14 +325,14 @@ proto.emit = function (value) { }; proto.onValue = function (value) { // Override me -}; +}; proto.onToken = function (token, value) { if(this.state === VALUE){ if(token === STRING || token === NUMBER || token === TRUE || token === FALSE || token === NULL){ if (this.value) { this.value[this.key] = value; } - this.emit(value); + this.emit(value); }else if(token === LEFT_BRACE){ this.push(); if (this.value) { @@ -322,7 +381,7 @@ proto.onToken = function (token, value) { if (token === COLON) { this.state = VALUE; } else { return this.parseError(token, value); } }else if(this.state === COMMA){ - if (token === COMMA) { + if (token === COMMA) { if (this.mode === ARRAY) { this.key++; this.state = VALUE; } else if (this.mode === OBJECT) { this.state = KEY; } diff --git a/node_modules/JSONStream/node_modules/jsonparse/package.json b/node_modules/JSONStream/node_modules/jsonparse/package.json index 65e97dd86..f60aa1ef7 100644 --- a/node_modules/JSONStream/node_modules/jsonparse/package.json +++ b/node_modules/JSONStream/node_modules/jsonparse/package.json @@ -14,14 +14,19 @@ ] ], "_from": "jsonparse@>=1.2.0 <2.0.0", - "_id": "jsonparse@1.2.0", + "_id": "jsonparse@1.3.0", "_inCache": true, "_location": "/JSONStream/jsonparse", + "_nodeVersion": "4.1.1", + "_npmOperationalInternal": { + "host": "packages-12-west.internal.npmjs.com", + "tmp": "tmp/jsonparse-1.3.0.tgz_1484597944748_0.925271877553314" + }, "_npmUser": { "name": "creationix", "email": "tim@creationix.com" }, - "_npmVersion": "1.4.28", + "_npmVersion": "2.14.4", "_phantomChildren": {}, "_requested": { "raw": "jsonparse@^1.2.0", @@ -35,8 +40,8 @@ "_requiredBy": [ "/JSONStream" ], - "_resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.2.0.tgz", - "_shasum": "5c0c5685107160e72fe7489bddea0b44c2bc67bd", + "_resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.0.tgz", + "_shasum": "85fc245b1d9259acc6941960b905adf64e7de0e8", "_shrinkwrap": null, "_spec": "jsonparse@^1.2.0", "_where": "/Users/zkat/Documents/code/npm/node_modules/JSONStream", @@ -55,14 +60,14 @@ }, "directories": {}, "dist": { - "shasum": "5c0c5685107160e72fe7489bddea0b44c2bc67bd", - "tarball": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.2.0.tgz" + "shasum": "85fc245b1d9259acc6941960b905adf64e7de0e8", + "tarball": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.0.tgz" }, "engines": [ "node >= 0.2.0" ], - "gitHead": "b3f4dc7b49300a549aea19a628d712009ca84ced", - "homepage": "https://github.com/creationix/jsonparse", + "gitHead": "69f02ca615aeeb4cbbe786ab42ce0592b44dc217", + "homepage": "https://github.com/creationix/jsonparse#readme", "license": "MIT", "main": "jsonparse.js", "maintainers": [ @@ -89,5 +94,5 @@ "json", "stream" ], - "version": "1.2.0" + "version": "1.3.0" } diff --git a/node_modules/JSONStream/node_modules/jsonparse/test/big-token.js b/node_modules/JSONStream/node_modules/jsonparse/test/big-token.js new file mode 100644 index 000000000..36046317e --- /dev/null +++ b/node_modules/JSONStream/node_modules/jsonparse/test/big-token.js @@ -0,0 +1,24 @@ +var stream = require('stream'); +var JsonParse = require('../jsonparse'); +var test = require('tape'); + +test('can handle large tokens without running out of memory', function (t) { + var parser = new JsonParse(); + var chunkSize = 1024; + var chunks = 1024 * 200; // 200mb + var quote = Buffer.from ? Buffer.from('"') : new Buffer('"'); + t.plan(1); + + parser.onToken = function (type, value) { + t.equal(value.length, chunkSize * chunks, 'token should be size of input json'); + t.end(); + }; + + parser.write(quote); + for (var i = 0; i < chunks; ++i) { + var buf = Buffer.alloc ? Buffer.alloc(chunkSize) : new Buffer(chunkSize); + buf.fill('a'); + parser.write(buf); + } + parser.write(quote); +}); diff --git a/node_modules/JSONStream/package.json b/node_modules/JSONStream/package.json index 75eacb3b0..91907f21c 100644 --- a/node_modules/JSONStream/package.json +++ b/node_modules/JSONStream/package.json @@ -2,50 +2,50 @@ "_args": [ [ { - "raw": "JSONStream@1.3.0", + "raw": "JSONStream@latest", "scope": null, "escapedName": "JSONStream", "name": "JSONStream", - "rawSpec": "1.3.0", - "spec": "1.3.0", - "type": "version" + "rawSpec": "latest", + "spec": "latest", + "type": "tag" }, - "/Users/rebecca/code/npm" + "/Users/zkat/Documents/code/npm" ] ], - "_from": "JSONStream@1.3.0", - "_id": "JSONStream@1.3.0", + "_from": "JSONStream@latest", + "_id": "JSONStream@1.3.1", "_inCache": true, "_location": "/JSONStream", - "_nodeVersion": "6.5.0", + "_nodeVersion": "6.9.4", "_npmOperationalInternal": { - "host": "packages-18-east.internal.npmjs.com", - "tmp": "tmp/JSONStream-1.3.0.tgz_1481845260408_0.7681232686154544" + "host": "packages-12-west.internal.npmjs.com", + "tmp": "tmp/JSONStream-1.3.1.tgz_1487992062630_0.4616028449963778" }, "_npmUser": { "name": "dominictarr", "email": "dominic.tarr@gmail.com" }, - "_npmVersion": "3.10.3", + "_npmVersion": "3.10.10", "_phantomChildren": {}, "_requested": { - "raw": "JSONStream@1.3.0", + "raw": "JSONStream@latest", "scope": null, "escapedName": "JSONStream", "name": "JSONStream", - "rawSpec": "1.3.0", - "spec": "1.3.0", - "type": "version" + "rawSpec": "latest", + "spec": "latest", + "type": "tag" }, "_requiredBy": [ "#USER", "/" ], - "_resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.0.tgz", - "_shasum": "680ab9ac6572a8a1a207e0b38721db1c77b215e5", + "_resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz", + "_shasum": "707f761e01dae9e16f1bcf93703b78c70966579a", "_shrinkwrap": null, - "_spec": "JSONStream@1.3.0", - "_where": "/Users/rebecca/code/npm", + "_spec": "JSONStream@latest", + "_where": "/Users/zkat/Documents/code/npm", "author": { "name": "Dominic Tarr", "email": "dominic.tarr@gmail.com", @@ -72,13 +72,13 @@ }, "directories": {}, "dist": { - "shasum": "680ab9ac6572a8a1a207e0b38721db1c77b215e5", - "tarball": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.0.tgz" + "shasum": "707f761e01dae9e16f1bcf93703b78c70966579a", + "tarball": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz" }, "engines": { "node": "*" }, - "gitHead": "3d5d3283d79e23da81fa6fc4b76bc1f44ff0047d", + "gitHead": "71ab5610d272bb47e64957e2191df6662ee64a90", "homepage": "http://github.com/dominictarr/JSONStream", "keywords": [ "json", @@ -109,5 +109,5 @@ "scripts": { "test": "set -e; for t in test/*.js; do echo '***' $t '***'; node $t; done" }, - "version": "1.3.0" + "version": "1.3.1" } diff --git a/node_modules/JSONStream/test/header_footer.js b/node_modules/JSONStream/test/header_footer.js index ef0187940..f18fc59e7 100644 --- a/node_modules/JSONStream/test/header_footer.js +++ b/node_modules/JSONStream/test/header_footer.js @@ -38,6 +38,7 @@ parser.on('data', function (data) { value: {rev: it.typeof('string')}, key:it.typeof('string') }) + it(headerCalled).equal(1) parsed.push(data) }) diff --git a/node_modules/JSONStream/test/keys.js b/node_modules/JSONStream/test/keys.js index 86b65b257..747723d11 100644 --- a/node_modules/JSONStream/test/keys.js +++ b/node_modules/JSONStream/test/keys.js @@ -41,7 +41,7 @@ test('keys via array', function(t) { test('path via array', function(t) { var stream = JSONStream.parse(['obj',{emitPath: true}]); - + var paths = []; var values = []; stream.on('data', function(data) { diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index bce58755c..53617f23d 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -273,14 +273,14 @@ } }, "JSONStream": { - "version": "1.3.0", - "from": "JSONStream@1.3.0", - "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.0.tgz", + "version": "1.3.1", + "from": "JSONStream@latest", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz", "dependencies": { "jsonparse": { - "version": "1.2.0", + "version": "1.3.0", "from": "jsonparse@>=1.2.0 <2.0.0", - "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.2.0.tgz" + "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.0.tgz" }, "through": { "version": "2.3.8", diff --git a/package.json b/package.json index 0f3d06001..b05589740 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "bin": "./bin/npm-cli.js", "dependencies": { "@npmcorp/move": "~1.0.0", - "JSONStream": "~1.3.0", + "JSONStream": "~1.3.1", "abbrev": "~1.1.0", "ansi-regex": "~2.1.1", "ansicolors": "~0.3.2", |