Skip to content

Commit

Permalink
src: skip revoke_data_object if uuid is not found
Browse files Browse the repository at this point in the history
Fix: nodejs#42206

PR-URL: nodejs#42212
Fixes: nodejs#42206
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Mestery <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
meixg authored and sxa committed Mar 7, 2022
1 parent 5b23e67 commit 0abc20b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
4 changes: 3 additions & 1 deletion src/node_blob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-blob-createobjecturl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0abc20b

Please sign in to comment.