mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/node): align input validation of Buffer.compare (#29275)
Some checks are pending
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
Some checks are pending
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
This commit is contained in:
parent
acd0c94b46
commit
1022decc79
4 changed files with 62 additions and 19 deletions
|
@ -382,25 +382,14 @@ const BufferIsBuffer = Buffer.isBuffer = function isBuffer(b) {
|
|||
};
|
||||
|
||||
const BufferCompare = Buffer.compare = function compare(a, b) {
|
||||
if (isUint8Array(a)) {
|
||||
a = BufferFrom(
|
||||
a,
|
||||
TypedArrayPrototypeGetByteOffset(a),
|
||||
TypedArrayPrototypeGetByteLength(a),
|
||||
);
|
||||
if (!isUint8Array(a)) {
|
||||
throw new codes.ERR_INVALID_ARG_TYPE("buf1", ["Buffer", "Uint8Array"], a);
|
||||
}
|
||||
if (isUint8Array(b)) {
|
||||
b = BufferFrom(
|
||||
b,
|
||||
TypedArrayPrototypeGetByteOffset(b),
|
||||
TypedArrayPrototypeGetByteLength(b),
|
||||
);
|
||||
}
|
||||
if (!BufferIsBuffer(a) || !BufferIsBuffer(b)) {
|
||||
throw new TypeError(
|
||||
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array',
|
||||
);
|
||||
|
||||
if (!isUint8Array(b)) {
|
||||
throw new ERR_INVALID_ARG_TYPE("buf2", ["Buffer", "Uint8Array"], b);
|
||||
}
|
||||
|
||||
if (a === b) {
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue