string.length !== Buffer.byteLength(string)
This commit is contained in:
parent
1cf538a60a
commit
6ea99721f1
@ -111,6 +111,9 @@ function Buffer (subject, encoding, legacy, slice_legacy) {
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
length = Buffer.byteLength(subject);
|
||||
break;
|
||||
|
||||
case 'object': // Assume object is an array
|
||||
length = subject.length;
|
||||
break;
|
||||
@ -186,7 +189,7 @@ Buffer.prototype.set = function set (i, v) {
|
||||
};
|
||||
|
||||
|
||||
// write(string, offset = 0, encoding = 'uft8')
|
||||
// write(string, offset = 0, encoding = 'utf8')
|
||||
Buffer.prototype.write = function write (string, offset, encoding) {
|
||||
if (!isFinite(offset)) {
|
||||
var swap = encoding;
|
||||
@ -195,11 +198,12 @@ Buffer.prototype.write = function write (string, offset, encoding) {
|
||||
}
|
||||
|
||||
offset || (offset = 0);
|
||||
encoding || (encoding = 'uft8');
|
||||
encoding || (encoding = 'utf8');
|
||||
|
||||
// Make sure we are not going to overflow
|
||||
var max_length = this.length - offset;
|
||||
if (string.length > max_length) {
|
||||
if (Buffer.byteLength(string) > max_length) {
|
||||
// FIXME: Char length !== byte length
|
||||
string = string.slice(0, max_length);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user