diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 4d443c80278385..af26a1bb7536b4 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -54,6 +54,7 @@ const { lazyDOMException, } = require('internal/util'); const { inspect } = require('internal/util/inspect'); +const { convertToInt } = require('internal/webidl'); const { codes: { @@ -239,6 +240,12 @@ class Blob { slice(start = 0, end = this[kLength], contentType = '') { if (!isBlob(this)) throw new ERR_INVALID_THIS('Blob'); + + // Coerce values to int + const opts = { __proto__: null, signed: true }; + start = convertToInt('start', start, 64, opts); + end = convertToInt('end', end, 64, opts); + if (start < 0) { start = MathMax(this[kLength] + start, 0); } else { diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index e7332606f64c28..bcf88699b2910c 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -483,6 +483,7 @@ assert.throws(() => new Blob({}), { assert.ok(blob.slice(0, 1).constructor === Blob); assert.ok(blob.slice(0, 1) instanceof Blob); + assert.ok(blob.slice(0, 1.5) instanceof Blob); } (async () => {