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: #42206

PR-URL: #42212
Fixes: #42206
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
meixg authored and danielleadams committed Apr 24, 2022
1 parent 137ca4e commit d4b1b5c
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 d4b1b5c

Please sign in to comment.