summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/integration/node_unit_tests.rs1
-rw-r--r--cli/tests/unit_node/buffer_test.ts12
-rw-r--r--ext/node/polyfills/internal/buffer.mjs26
3 files changed, 14 insertions, 25 deletions
diff --git a/cli/tests/integration/node_unit_tests.rs b/cli/tests/integration/node_unit_tests.rs
index 6d604b47b..1bb072324 100644
--- a/cli/tests/integration/node_unit_tests.rs
+++ b/cli/tests/integration/node_unit_tests.rs
@@ -47,6 +47,7 @@ util::unit_test_factory!(
_fs_watch_test = _fs / _fs_watch_test,
_fs_write_test = _fs / _fs_write_test,
async_hooks_test,
+ buffer_test,
child_process_test,
crypto_cipher_test = crypto / crypto_cipher_test,
crypto_hash_test = crypto / crypto_hash_test,
diff --git a/cli/tests/unit_node/buffer_test.ts b/cli/tests/unit_node/buffer_test.ts
new file mode 100644
index 000000000..1d7571f6a
--- /dev/null
+++ b/cli/tests/unit_node/buffer_test.ts
@@ -0,0 +1,12 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+import { Buffer } from "node:buffer";
+import { assertEquals } from "../../../test_util/std/testing/asserts.ts";
+
+Deno.test({
+ name: "[node/buffer] slice with infinity returns empty buffer",
+ fn() {
+ const buf = Buffer.from([1, 2, 3, 4, 5]);
+ assertEquals(buf.slice(Infinity).length, 0);
+ },
+});
diff --git a/ext/node/polyfills/internal/buffer.mjs b/ext/node/polyfills/internal/buffer.mjs
index 73116e552..32396beaa 100644
--- a/ext/node/polyfills/internal/buffer.mjs
+++ b/ext/node/polyfills/internal/buffer.mjs
@@ -860,31 +860,7 @@ function _hexSlice(buf, start, end) {
}
Buffer.prototype.slice = function slice(start, end) {
- const len = this.length;
- start = ~~start;
- end = end === void 0 ? len : ~~end;
- if (start < 0) {
- start += len;
- if (start < 0) {
- start = 0;
- }
- } else if (start > len) {
- start = len;
- }
- if (end < 0) {
- end += len;
- if (end < 0) {
- end = 0;
- }
- } else if (end > len) {
- end = len;
- }
- if (end < start) {
- end = start;
- }
- const newBuf = this.subarray(start, end);
- Object.setPrototypeOf(newBuf, Buffer.prototype);
- return newBuf;
+ return this.subarray(start, end);
};
Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(