Socket
Socket
Sign inDemoInstall

msgpack5

Package Overview
Dependencies
9
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.0 to 5.2.0

test/prefer-map.js

5

index.js

@@ -21,3 +21,4 @@ 'use strict'

// timestamp ext format (-1)
disableTimestampEncoding: false
disableTimestampEncoding: false,
preferMap: false
}

@@ -76,3 +77,3 @@

encode: buildEncode(encodingTypes, options),
decode: buildDecode(decodingTypes),
decode: buildDecode(decodingTypes, options),
register,

@@ -79,0 +80,0 @@ registerEncoder,

27

lib/decoder.js

@@ -40,3 +40,3 @@ 'use strict'

module.exports = function buildDecode (decodingTypes) {
module.exports = function buildDecode (decodingTypes, options) {
return decode

@@ -76,4 +76,4 @@

const headerSize = offset - initialOffset
// we have an array with less than 15 elements
return decodeMap(buf, offset, length, headerSize)
// we have a map with less than 15 elements
return decodeMap(buf, offset, length, headerSize, options)
}

@@ -83,3 +83,3 @@ if ((first & 0xf0) === 0x90) {

const headerSize = offset - initialOffset
// we have a map with less than 15 elements
// we have an array with less than 15 elements
return decodeArray(buf, offset, length, headerSize)

@@ -144,3 +144,3 @@ }

// console.log(offset - initialOffset)
return decodeMap(buf, offset, length, 3)
return decodeMap(buf, offset, length, 3, options)

@@ -150,3 +150,3 @@ case 0xdf:

offset += 4
return decodeMap(buf, offset, length, 5)
return decodeMap(buf, offset, length, 5, options)
}

@@ -174,3 +174,3 @@ }

function decodeMap (buf, offset, length, headerLength) {
function decodeMap (buf, offset, length, headerLength, options) {
const _temp = decodeArray(buf, offset, 2 * length, headerLength)

@@ -180,7 +180,10 @@ if (!_temp) return null

var isPlainObject = true
for (let i = 0; i < 2 * length; i += 2) {
if (typeof result[i] !== 'string') {
isPlainObject = false
break
var isPlainObject = !options.preferMap
if (isPlainObject) {
for (let i = 0; i < 2 * length; i += 2) {
if (typeof result[i] !== 'string') {
isPlainObject = false
break
}
}

@@ -187,0 +190,0 @@ }

@@ -65,4 +65,6 @@ 'use strict'

if (keys.every(item => typeof item === 'string')) {
console.warn('Map with string only keys will be deserialized as an object!')
if (!options.preferMap) {
if (keys.every(item => typeof item === 'string')) {
console.warn('Map with string only keys will be deserialized as an object!')
}
}

@@ -69,0 +71,0 @@

{
"name": "msgpack5",
"version": "5.1.0",
"version": "5.2.0",
"description": "A msgpack v5 implementation for node.js and the browser, with extension points",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -113,2 +113,3 @@ msgpack5&nbsp;&nbsp;[![CI](https://github.com/mcollina/msgpack5/workflows/CI/badge.svg)](https://github.com/mcollina/msgpack5/actions?query=workflow%3ACI)

- `disableTimestampEncoding`, a boolean that when set disables the encoding of Dates into the [timestamp extension type](https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type). Defaults to false.
- `preferMap`, a boolean that forces all maps to be decoded to `Map`s rather than plain objects. This ensures that `decode(encode(new Map())) instanceof Map` and that iteration order is preserved. Defaults to false.

@@ -115,0 +116,0 @@ -------------------------------------------------------

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