【发布时间】:2021-12-22 04:37:09
【问题描述】:
我编写了下面的代码来说明连接这两个字符串时发生的这种行为。
const getBytes = x => {
let buf = Buffer.from(x);
const n = [];
for (const value of buf.values()) {
n.push(value);
}
return [n, parseInt(buf.toString('hex'), 16)];
};
let x = unescape('%uDB40');
let y = unescape('%uDD31');
console.log(typeof(x), typeof(y));
console.log(Buffer.from(x), getBytes(x), );
console.log(Buffer.from(y), getBytes(y));
console.log(Buffer.from(x+y), getBytes(x+y));
结果是:
string string
<Buffer ef bf bd> [ [ 239, 191, 189 ], 15712189 ]
<Buffer ef bf bd> [ [ 239, 191, 189 ], 15712189 ]
<Buffer f3 a0 84 b1> [ [ 243, 160, 132, 177 ], 4087383217 ]
我无法理解它是如何以完全不同的结果结束的,这使我无法成功移植此行为。
【问题讨论】:
标签: javascript hex emulation