Socket
Socket
Sign inDemoInstall

bson

Package Overview
Dependencies
4
Maintainers
4
Versions
162
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0-rc7 to 4.0.0-rc8

lib/validate_utf8.js

4

lib/bson.js

@@ -10,3 +10,3 @@ 'use strict';

const BSONRegExp = require('./regexp');
const Symbol = require('./symbol');
const BSONSymbol = require('./symbol');
const Int32 = require('./int_32');

@@ -254,3 +254,3 @@ const Code = require('./code');

Map,
Symbol,
BSONSymbol,
DBRef,

@@ -257,0 +257,0 @@ Binary,

@@ -41,11 +41,13 @@ 'use strict';

if (typeof value === 'number') {
if (options.relaxed) {
return value;
}
// if it's an integer, should interpret as smallest BSON integer
// that can represent it exactly. (if out of range, interpret as double.)
if (Math.floor(value) === value) {
let int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX,
int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX;
if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) return new Int32(value);
if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX) return new Long.fromNumber(value);
}
if (int32Range) return options.strict ? new Int32(value) : value;
if (int64Range) return options.strict ? new Long.fromNumber(value) : value;
}
// If the number is a non-integer or out of integer range, should interpret as BSON Double.

@@ -52,0 +54,0 @@ return new Double(value);

@@ -37,2 +37,11 @@ 'use strict';

function makeObjectIdError(invalidString, index) {
const invalidCharacter = invalidString[index];
return new TypeError(
`ObjectId string "${invalidString}" contains invalid character "${invalidCharacter}" with character code (${invalidString.charCodeAt(
index
)}). All character codes for a non-hex string must be less than 256.`
);
}
/**

@@ -115,3 +124,7 @@ * A class representation of the BSON ObjectId type.

for (let i = 0; i < this.id.length; i++) {
hexString += hexTable[this.id.charCodeAt(i)];
const hexChar = hexTable[this.id.charCodeAt(i)];
if (typeof hexChar !== 'string') {
throw makeObjectIdError(this.id, i);
}
hexString += hexChar;
}

@@ -333,3 +346,3 @@

if (id instanceof _Buffer) {
if (id instanceof _Buffer && id.length === 12) {
return true;

@@ -336,0 +349,0 @@ }

@@ -8,3 +8,3 @@ 'use strict';

const ObjectId = require('../objectid');
const Symbol = require('../symbol');
const BSONSymbol = require('../symbol');
const BSONRegExp = require('../regexp');

@@ -150,3 +150,3 @@ const Code = require('../code');

}
} else if (value instanceof Symbol || value['_bsontype'] === 'Symbol') {
} else if (value instanceof BSONSymbol || value['_bsontype'] === 'Symbol') {
return (

@@ -153,0 +153,0 @@ (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) +

@@ -17,2 +17,3 @@ 'use strict';

const constants = require('../constants');
const validateUtf8 = require('../validate_utf8').validateUtf8;

@@ -138,9 +139,8 @@ // Internal long versions

const s = buffer.toString('utf8', index, index + stringSize - 1);
for (i = 0; i < s.length; i++) {
if (s.charCodeAt(i) === 0xfffd) {
throw new Error('Invalid UTF-8 string in BSON document');
}
if (!validateUtf8(buffer, index, index + stringSize - 1)) {
throw new Error('Invalid UTF-8 string in BSON document');
}
const s = buffer.toString('utf8', index, index + stringSize - 1);
object[name] = s;

@@ -552,2 +552,5 @@ index = index + stringSize;

// Namespace
if (!validateUtf8(buffer, index, index + stringSize - 1)) {
throw new Error('Invalid UTF-8 string in BSON document');
}
const namespace = buffer.toString('utf8', index, index + stringSize - 1);

@@ -564,7 +567,2 @@ // Update parse index position

index = index + 12;
for (i = 0; i < namespace.length; i++) {
if (namespace.charCodeAt(i) === 0xfffd) {
throw new Error('Invalid UTF-8 string in BSON document');
}
}

@@ -571,0 +569,0 @@ // Upgrade to DBRef type

@@ -254,2 +254,8 @@ 'use strict';

function serializeMinMax(buffer, key, value, index, isArray) {
console.log({
value,
MinKey,
isMinKey: value instanceof MinKey
});
// Write the type of either min or max key

@@ -256,0 +262,0 @@ if (value === null) {

@@ -5,3 +5,3 @@ 'use strict';

*/
class Symbol {
class BSONSymbol {
/**

@@ -58,7 +58,7 @@ * Create a Symbol type

static fromExtendedJSON(doc) {
return new Symbol(doc.$symbol);
return new BSONSymbol(doc.$symbol);
}
}
Object.defineProperty(Symbol.prototype, '_bsontype', { value: 'Symbol' });
module.exports = Symbol;
Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
module.exports = BSONSymbol;

@@ -14,3 +14,3 @@ {

],
"version": "4.0.0-rc7",
"version": "4.0.0-rc8",
"author": "Christian Amor Kvalheim <christkv@gmail.com>",

@@ -25,27 +25,26 @@ "license": "Apache-2.0",

"devDependencies": {
"babel-core": "^6.26.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.1",
"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
"benchmark": "^2.1.4",
"chai": "^4.1.2",
"conventional-changelog-cli": "^1.3.5",
"chai": "^4.2.0",
"dmd-clear": "^0.1.2",
"eslint": "^4.7.2",
"eslint-plugin-prettier": "^2.3.1",
"eslint": "^5.8.0",
"eslint-plugin-prettier": "^3.0.0",
"istanbul": "^0.4.5",
"jsdoc-to-markdown": "^4.0.1",
"karma": "^2.0.4",
"karma": "^3.1.1",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-rollup-preprocessor": "^6.0.0",
"mocha": "^3.5.3",
"prettier": "~1.12.0",
"rollup": "^0.56.2",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^8.3.0",
"rollup-plugin-json": "^3.0.0",
"karma-rollup-preprocessor": "^6.1.0",
"mocha": "^5.2.0",
"prettier": "^1.15.1",
"rollup": "^0.67.0",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.2.1",
"rollup-plugin-node-resolve": "^3.0.3"
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^3.4.0",
"standard-version": "^4.4.0"
},

@@ -62,15 +61,15 @@ "config": {

"engines": {
"node": ">=4.0.0"
"node": ">=6.9.0"
},
"scripts": {
"docs": "jsdoc2md --heading-depth 3 --template tools/README.hbs --plugin dmd-clear --files lib/bson.js lib/extended_json.js > README.md",
"test": "npm run-script test-node && npm run-script test-browser",
"test": "npm run-script lint && npm run-script test-node && npm run-script test-browser",
"test-node": "mocha ./test/node",
"test-browser": "karma start",
"test-browser": "npm run-script build && karma start",
"build": "rollup -c",
"lint": "eslint lib test",
"format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
"changelog": "conventional-changelog -p angular -i HISTORY.md -s",
"coverage": "istanbul cover _mocha -- --recursive --ui tdd test/node",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"release": "standard-version -i HISTORY.md"
},

@@ -77,0 +76,0 @@ "dependencies": {

# BSON parser
**NOTE: This is usage documentation for the current 4.0.0 beta. You can find documentation for the 3.0 version of js-bson [here](https://github.com/mongodb/js-bson/blob/v3.0.2/README.md)**
BSON is short for Bin­ary JSON and is the bin­ary-en­coded seri­al­iz­a­tion of JSON-like doc­u­ments. You can learn more about it in [the specification](http://bsonspec.org).

@@ -9,2 +11,19 @@

### Table of Contents
- [Usage](#usage)
- [Bugs/Feature Requests](#bugs--feature-requests)
- [Installation](#installation)
- [Documentation](#documentation)
- [FAQ](#faq)
## Bugs / Feature Requests
Think you've found a bug? Want to see a new feature in `bson`? Please open a case in our issue management tool, JIRA:
1. Create an account and login: [jira.mongodb.org](https://jira.mongodb.org)
2. Navigate to the NODE project: [jira.mongodb.org/browse/NODE](https://jira.mongodb.org/browse/NODE)
3. Click **Create Issue** - Please provide as much information as possible about the issue and how to reproduce it.
Bug reports in JIRA for all driver projects (i.e. NODE, PYTHON, CSHARP, JAVA) and the Core Server (i.e. SERVER) project are **public**.
## Usage

@@ -11,0 +30,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc