From d4b1b5cf85a2980f4f149ce24624e5e9d0a9da9f Mon Sep 17 00:00:00 2001 From: Xuguang Mei Date: Sun, 6 Mar 2022 17:24:42 +0800 Subject: [PATCH] src: skip revoke_data_object if uuid is not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix: https://github.com/nodejs/node/issues/42206 PR-URL: https://github.com/nodejs/node/pull/42212 Fixes: https://github.com/nodejs/node/issues/42206 Reviewed-By: Juan José Arboleda Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: Antoine du Hamel Reviewed-By: Mestery Reviewed-By: Darshan Sen --- doc/api/url.md | 3 ++- src/node_blob.cc | 4 +++- test/parallel/test-blob-createobjecturl.js | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/api/url.md b/doc/api/url.md index 1fd63a842fb200..81d30b8abb92bb 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -659,7 +659,8 @@ added: v16.7.0 * `id` {string} A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`. -Removes the stored {Blob} identified by the given ID. +Removes the stored {Blob} identified by the given ID. Attempting to revoke a +ID that isn’t registered will silently fail. ### Class: `URLSearchParams` diff --git a/src/node_blob.cc b/src/node_blob.cc index 4643da4c17496c..ee61437f402fcd 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -444,7 +444,9 @@ void BlobBindingData::store_data_object( } void BlobBindingData::revoke_data_object(const std::string& uuid) { - CHECK_NE(data_objects_.find(uuid), data_objects_.end()); + if (data_objects_.find(uuid) == data_objects_.end()) { + return; + } data_objects_.erase(uuid); CHECK_EQ(data_objects_.find(uuid), data_objects_.end()); } diff --git a/test/parallel/test-blob-createobjecturl.js b/test/parallel/test-blob-createobjecturl.js index a8fd377dd3ef70..70c64b138db1ac 100644 --- a/test/parallel/test-blob-createobjecturl.js +++ b/test/parallel/test-blob-createobjecturl.js @@ -29,6 +29,10 @@ const assert = require('assert'); Buffer.from(await otherBlob.arrayBuffer()).toString(), 'hello'); URL.revokeObjectURL(id); + + // should do nothing + URL.revokeObjectURL(id); + assert.strictEqual(resolveObjectURL(id), undefined); // Leaving a Blob registered should not cause an assert