native-buffer-browserify
Advanced tools
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() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
1211833
17733
0
+ Addedbase64-js@0.0.8(transitive)
Updatedbase64-js@~0.0.4