Socket
Socket
Sign inDemoInstall

jsonparse

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.0.6

test/offset.js

44

jsonparse.js

@@ -26,4 +26,4 @@ /*global Buffer*/

var NULL1 = C.NULL1 = 0x41;
var NULL2 = C.NULL3 = 0x42;
var NULL3 = C.NULL2 = 0x43;
var NULL2 = C.NULL2 = 0x42;
var NULL3 = C.NULL3 = 0x43;
var NUMBER1 = C.NUMBER1 = 0x51;

@@ -67,2 +67,3 @@ var NUMBER2 = C.NUMBER2 = 0x52;

this.unicode = undefined; // unicode escapes
this.stringLength = 0;

@@ -75,2 +76,3 @@ // For number parsing

this.negativeExponent = undefined;
this.numberLength = 0;

@@ -84,2 +86,5 @@ this.key = undefined;

this.temp_buffs = { "2": new Buffer(2), "3": new Buffer(3), "4": new Buffer(4) }; // for rebuilding chars split before boundary is reached
// Stream offset
this.offset = -1;
}

@@ -99,2 +104,3 @@ var proto = Parser.prototype;

n = buffer[i];
this.offset++;
if(n === 0x7b){ this.onToken(LEFT_BRACE, "{"); // {

@@ -109,3 +115,3 @@ }else if(n === 0x7d){ this.onToken(RIGHT_BRACE, "}"); // }

}else if(n === 0x6e){ this.tState = NULL1; // n
}else if(n === 0x22){ this.string = ""; this.tState = STRING1; // "
}else if(n === 0x22){ this.string = ""; this.tState = STRING1; this.stringLength = 0; // "
}else if(n === 0x2d){ this.negative = true; this.tState = NUMBER1; // -

@@ -121,2 +127,3 @@ }else if(n === 0x30){ this.magnatude = 0; this.tState = NUMBER2; // 0

}else if (this.tState === STRING1){ // After open quote
this.stringLength++;
n = buffer[i]; // get current byte from buffer

@@ -132,2 +139,3 @@ // check for carry over of a multi byte char split between data chunks

i = i + j - 1;
this.stringLength += 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

@@ -146,4 +154,5 @@ if ((n >= 194) && (n <= 223)) this.bytes_in_sequence = 2;

i = i + this.bytes_in_sequence - 1;
this.stringLength += this.bytes_in_sequence - 1;
}
} else if (n === 0x22) { this.tState = START; this.onToken(STRING, this.string); this.string = undefined; }
} else if (n === 0x22) { this.tState = START; this.onToken(STRING, this.string); this.offset += this.stringLength; this.string = undefined; }
else if (n === 0x5c) { this.tState = STRING2; }

@@ -153,2 +162,3 @@ else if (n >= 0x20) { this.string += String.fromCharCode(n); }

}else if (this.tState === STRING2){ // After backslash
this.stringLength++;
n = buffer[i];

@@ -168,2 +178,3 @@ if(n === 0x22){ this.string += "\""; this.tState = STRING1;

}else if (this.tState === STRING3 || this.tState === STRING4 || this.tState === STRING5 || this.tState === STRING6){ // unicode hex codes
this.stringLength++;
n = buffer[i];

@@ -174,2 +185,3 @@ // 0-9 A-F a-f

if (this.tState++ === STRING6) {
this.stringLength++;
this.string += String.fromCharCode(parseInt(this.unicode, 16));

@@ -184,2 +196,3 @@ this.unicode = undefined;

n = buffer[i];
this.numberLength++;
if (n === 0x30) { this.magnatude = 0; this.tState = NUMBER2; }

@@ -190,2 +203,3 @@ else if (n > 0x30 && n < 0x40) { this.magnatude = n - 0x30; this.tState = NUMBER3; }

n = buffer[i];
this.numberLength++;
if(n === 0x2e){ // .

@@ -198,2 +212,4 @@ this.position = 0.1; this.tState = NUMBER4;

this.onToken(NUMBER, 0);
this.offset += this.numberLength - 1;
this.numberLength = 0;
this.magnatude = undefined;

@@ -205,2 +221,3 @@ this.negative = undefined;

n = buffer[i];
this.numberLength++;
if(n === 0x2e){ // .

@@ -219,2 +236,4 @@ this.position = 0.1; this.tState = NUMBER4;

this.onToken(NUMBER, this.magnatude);
this.offset += this.numberLength - 1;
this.numberLength = 0;
this.magnatude = undefined;

@@ -226,2 +245,3 @@ i--;

n = buffer[i];
this.numberLength++;
if (n >= 0x30 && n < 0x40) { // 0-9

@@ -234,2 +254,3 @@ this.magnatude += this.position * (n - 0x30);

n = buffer[i];
this.numberLength++;
if (n >= 0x30 && n < 0x40) { // 0-9

@@ -247,2 +268,4 @@ this.magnatude += this.position * (n - 0x30);

this.onToken(NUMBER, this.negative ? -this.magnatude : this.magnatude);
this.offset += this.numberLength - 1;
this.numberLength = 0;
this.magnatude = undefined;

@@ -254,2 +277,3 @@ this.position = undefined;

n = buffer[i];
this.numberLength++;
if (n === 0x2b || n === 0x2d) { // +/-

@@ -266,2 +290,3 @@ if (n === 0x2d) { this.negativeExponent = true; }

n = buffer[i];
this.numberLength++;
if (n >= 0x30 && n < 0x40) { // 0-9

@@ -274,2 +299,3 @@ this.exponent = this.exponent * 10 + (n - 0x30);

n = buffer[i];
this.numberLength++;
if (n >= 0x30 && n < 0x40) { // 0-9

@@ -291,2 +317,4 @@ this.exponent = this.exponent * 10 + (n - 0x30);

this.onToken(NUMBER, this.magnatude);
this.offset += this.numberLength - 1;
this.numberLength = 0;
this.magnatude = undefined;

@@ -302,3 +330,3 @@ i--;

}else if (this.tState === TRUE3){ // e
if (buffer[i] === 0x65) { this.tState = START; this.onToken(TRUE, true); }
if (buffer[i] === 0x65) { this.tState = START; this.onToken(TRUE, true); this.offset+= 3; }
else { this.charError(buffer, i); }

@@ -315,3 +343,3 @@ }else if (this.tState === FALSE1){ // a

}else if (this.tState === FALSE4){ // e
if (buffer[i] === 0x65) { this.tState = START; this.onToken(FALSE, false); }
if (buffer[i] === 0x65) { this.tState = START; this.onToken(FALSE, false); this.offset+= 4; }
else { this.charError(buffer, i); }

@@ -325,3 +353,3 @@ }else if (this.tState === NULL1){ // u

}else if (this.tState === NULL3){ // l
if (buffer[i] === 0x6c) { this.tState = START; this.onToken(NULL, null); }
if (buffer[i] === 0x6c) { this.tState = START; this.onToken(NULL, null); this.offset += 3; }
else { this.charError(buffer, i); }

@@ -428,2 +456,4 @@ }

Parser.C = C;
module.exports = Parser;

2

package.json

@@ -5,3 +5,3 @@ {

"tags": ["json", "stream"],
"version": "0.0.5",
"version": "0.0.6",
"author": "Tim Caswell <tim@creationix.com>",

@@ -8,0 +8,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc