Socket
Socket
Sign inDemoInstall

native-buffer-browserify

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

native-buffer-browserify - npm Package Compare versions

Comparing version 2.0.5 to 2.0.7

10

index.js

@@ -923,10 +923,14 @@ var base64 = require('base64-js')

var byteArray = []
for (var i = 0; i < str.length; i++)
if (str.charCodeAt(i) <= 0x7F)
for (var i = 0; i < str.length; i++) {
var b = str.charCodeAt(i)
if (b <= 0x7F)
byteArray.push(str.charCodeAt(i))
else {
var h = encodeURIComponent(str.charAt(i)).substr(1).split('%')
var start = i
if (b >= 0xD800 && b <= 0xDFFF) i++
var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
for (var j = 0; j < h.length; j++)
byteArray.push(parseInt(h[j], 16))
}
}
return byteArray

@@ -933,0 +937,0 @@ }

{
"name": "native-buffer-browserify",
"version": "2.0.5",
"version": "2.0.7",
"description": "buffer module compatibility for browserify (backed by ArrayBuffer so its fast!)",
"main": "index.js",
"dependencies": {
"base64-js": "git://github.com/feross/base64-js.git",
"base64-js": "~0.0.4",
"ieee754": "~1.1.1"

@@ -9,0 +9,0 @@ },

@@ -33,7 +33,7 @@ native-buffer-browserify

By augmenting the instances, we can avoid modifying the Uint8Array prototype.
By augmenting the instances, we can avoid modifying the `Uint8Array` prototype.
## Important Differences
- **Use `Buffer.isBuffer` instead of `instanceof Buffer`.** `instanceof Buffer` doesn’t work because the Buffer constructor returns a `Uint8Array` (as discussed above) for performance reasons. In node `Buffer.isBuffer` just does `instanceof Buffer`, but in browserify we use a `Buffer.isBuffer` shim that detects our special `Uint8Array`-based Buffers.
- **Use `Buffer.isBuffer` instead of `instanceof Buffer`.** The Buffer constructor returns a `Uint8Array` (as discussed above) for performance reasons, so `instanceof Buffer` won't work. In node `Buffer.isBuffer` just does `instanceof Buffer`, but in browserify we use a `Buffer.isBuffer` shim that detects our special `Uint8Array`-based Buffers.
- **Don't rely on `slice()` to modify the memory of the parent buffer.** If the browser is using the Typed Array implementation then modifying a buffer created by `slice()` will modify the original memory, [just like in Node](http://nodejs.org/api/buffer.html#buffer_buf_slice_start_end). But for the Object implementation (used in unsupported browsers), this is not possible. Therefore, do not rely on this behavior until browser support gets better. (Note: currently even Firefox isn't using the Typed Array implementation because of [this bug](https://bugzilla.mozilla.org/show_bug.cgi?id=952403).)

@@ -40,0 +40,0 @@

@@ -264,1 +264,35 @@ var B = require('../index.js').Buffer

})
test('detect utf16 surrogate pairs', function(t) {
t.plan(1)
var text = '\uD83D\uDE38' + '\uD83D\uDCAD' + '\uD83D\uDC4D'
var buf = new B(text)
t.equal(text, buf.toString())
t.end()
})
test('throw on orphaned utf16 surrogate lead code point', function(t) {
t.plan(1)
var text = '\uD83D\uDE38' + '\uD83D' + '\uD83D\uDC4D'
var err
try {
var buf = new B(text)
} catch (e) {
err = e
}
t.equal(err instanceof URIError, true)
t.end()
})
test('throw on orphaned utf16 surrogate trail code point', function(t) {
t.plan(1)
var text = '\uD83D\uDE38' + '\uDCAD' + '\uD83D\uDC4D'
var err
try {
var buf = new B(text)
} catch (e) {
err = e
}
t.equal(err instanceof URIError, true)
t.end()
})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc