diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts index 9f9b605f9a..193e606896 100644 --- a/cli/tests/unit/permissions_test.ts +++ b/cli/tests/unit/permissions_test.ts @@ -75,19 +75,14 @@ Deno.test(function permissionStatusIllegalConstructor() { assertEquals(Deno.PermissionStatus.length, 0); }); +// Regression test for https://github.com/denoland/deno/issues/17020 Deno.test(async function permissionURL() { - await Deno.permissions.query({ - name: "read", - path: new URL(".", import.meta.url), - }); - await Deno.permissions.query({ - name: "write", - path: new URL(".", import.meta.url), - }); - await Deno.permissions.query({ - name: "run", - command: new URL(".", import.meta.url), - }); + const path = new URL(".", import.meta.url); + + await Deno.permissions.query({ name: "read", path }); + await Deno.permissions.query({ name: "write", path }); + await Deno.permissions.query({ name: "ffi", path }); + await Deno.permissions.query({ name: "run", command: path }); }); Deno.test(async function permissionDescriptorValidation() { diff --git a/runtime/js/10_permissions.js b/runtime/js/10_permissions.js index d6ab33dcfe..c2ce6cef0d 100644 --- a/runtime/js/10_permissions.js +++ b/runtime/js/10_permissions.js @@ -161,6 +161,20 @@ ArrayPrototypeIncludes(permissionNames, desc.name); } + /** + * @param {Deno.PermissionDescriptor} desc + * @returns {desc is Deno.PermissionDescriptor} + */ + function formDescriptor(desc) { + if ( + desc.name === "read" || desc.name === "write" || desc.name === "ffi" + ) { + desc.path = pathFromURL(desc.path); + } else if (desc.name === "run") { + desc.command = pathFromURL(desc.command); + } + } + class Permissions { constructor(key = null) { if (key != illegalConstructorKey) { @@ -177,13 +191,7 @@ ); } - if ( - desc.name === "read" || desc.name === "write" || desc.name === "ffi" - ) { - desc.path = pathFromURL(desc.path); - } else if (desc.name === "run") { - desc.command = pathFromURL(desc.command); - } + formDescriptor(desc); const state = opQuery(desc); return PromiseResolve(cache(desc, state)); @@ -198,11 +206,7 @@ ); } - if (desc.name === "read" || desc.name === "write") { - desc.path = pathFromURL(desc.path); - } else if (desc.name === "run") { - desc.command = pathFromURL(desc.command); - } + formDescriptor(desc); const state = opRevoke(desc); return PromiseResolve(cache(desc, state)); @@ -217,11 +221,7 @@ ); } - if (desc.name === "read" || desc.name === "write") { - desc.path = pathFromURL(desc.path); - } else if (desc.name === "run") { - desc.command = pathFromURL(desc.command); - } + formDescriptor(desc); const state = opRequest(desc); return PromiseResolve(cache(desc, state));