From 1abcbb04b61b940c13b305c15ce752f1fd413d2e Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Fri, 16 Sep 2022 12:46:38 +0100 Subject: [PATCH] fix(runtime): fix permission status cache keys (#15899) --- cli/tests/unit/permissions_test.ts | 8 ++++++++ runtime/js/10_permissions.js | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts index 458ef2f28e..551e9bdcd8 100644 --- a/cli/tests/unit/permissions_test.ts +++ b/cli/tests/unit/permissions_test.ts @@ -86,3 +86,11 @@ Deno.test(async function permissionDescriptorValidation() { } } }); + +// Regression test for https://github.com/denoland/deno/issues/15894. +Deno.test(async function permissionStatusObjectsNotEqual() { + assert( + await Deno.permissions.query({ name: "env", variable: "A" }) != + await Deno.permissions.query({ name: "env", variable: "B" }), + ); +}); diff --git a/runtime/js/10_permissions.js b/runtime/js/10_permissions.js index af66c9d2e9..2573816dfb 100644 --- a/runtime/js/10_permissions.js +++ b/runtime/js/10_permissions.js @@ -122,12 +122,18 @@ function cache(desc, state) { let { name: key } = desc; if ( - (desc.name === "read" || desc.name === "write") && + (desc.name === "read" || desc.name === "write" || desc.name === "ffi") && ReflectHas(desc, "path") ) { - key += `-${desc.path}`; + key += `-${desc.path}&`; } else if (desc.name === "net" && desc.host) { - key += `-${desc.host}`; + key += `-${desc.host}&`; + } else if (desc.name === "run" && desc.command) { + key += `-${desc.command}&`; + } else if (desc.name === "env" && desc.variable) { + key += `-${desc.variable}&`; + } else { + key += "$"; } if (MapPrototypeHas(statusCache, key)) { const status = MapPrototypeGet(statusCache, key);