Skip to content

Commit 0d1a522

Browse files
authored
revert: allow URL for permissions (#11600)
Revert changes to "net" permissions in regards to handling URLs introduced in 15b0e61.
1 parent 2b53602 commit 0d1a522

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

cli/dts/lib.deno.ns.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ declare namespace Deno {
21592159
* "github.com"
21602160
* "deno.land:8080"
21612161
*/
2162-
host?: string | URL;
2162+
host?: string;
21632163
}
21642164

21652165
export interface EnvPermissionDescriptor {

cli/dts/lib.deno.unstable.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ declare namespace Deno {
10411041
* });
10421042
* ```
10431043
*/
1044-
net?: "inherit" | boolean | Array<string | URL>;
1044+
net?: "inherit" | boolean | string[];
10451045

10461046
/** Specifies if the `plugin` permission should be requested or revoked.
10471047
* If set to `"inherit"`, the current `plugin` permission will be inherited.
@@ -1136,7 +1136,7 @@ declare interface WorkerOptions {
11361136
*
11371137
* For example: `["https://deno.land", "localhost:8080"]`.
11381138
*/
1139-
net?: "inherit" | boolean | Array<string | URL>;
1139+
net?: "inherit" | boolean | string[];
11401140
plugin?: "inherit" | boolean;
11411141
read?: "inherit" | boolean | Array<string | URL>;
11421142
run?: "inherit" | boolean | Array<string | URL>;

cli/tests/unit/permissions_test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,4 @@ unitTest(async function permissionURL() {
7171
name: "run",
7272
command: new URL(".", import.meta.url),
7373
});
74-
await Deno.permissions.query({
75-
name: "net",
76-
host: new URL("https://deno.land/foo"),
77-
});
7874
});

runtime/js/11_workers.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@
9494
value = ArrayPrototypeMap(value, (route) => {
9595
if (route instanceof URL) {
9696
if (permission === "net") {
97-
route = route.host;
98-
}
99-
if (permission === "env") {
97+
throw new Error(
98+
`Expected 'string' for net permission, received 'URL'`,
99+
);
100+
} else if (permission === "env") {
100101
throw new Error(
101102
`Expected 'string' for env permission, received 'URL'`,
102103
);
@@ -124,12 +125,12 @@
124125
write = "inherit",
125126
}) {
126127
return {
127-
env: parseArrayPermission(env, "env"),
128+
env: parseUnitPermission(env, "env"),
128129
hrtime: parseUnitPermission(hrtime, "hrtime"),
129130
net: parseArrayPermission(net, "net"),
130131
plugin: parseUnitPermission(plugin, "plugin"),
131132
read: parseArrayPermission(read, "read"),
132-
run: parseArrayPermission(run, "run"),
133+
run: parseUnitPermission(run, "run"),
133134
write: parseArrayPermission(write, "write"),
134135
};
135136
}

runtime/js/40_permissions.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@
167167
desc.path = pathFromURL(desc.path);
168168
} else if (desc.name === "run") {
169169
desc.command = pathFromURL(desc.command);
170-
} else if (desc.name === "net") {
171-
if (desc.host instanceof URL) {
172-
desc.host = desc.host.host;
173-
}
174170
}
175171

176172
const state = opQuery(desc);
@@ -190,10 +186,6 @@
190186
desc.path = pathFromURL(desc.path);
191187
} else if (desc.name === "run") {
192188
desc.command = pathFromURL(desc.command);
193-
} else if (desc.name === "net") {
194-
if (desc.host instanceof URL) {
195-
desc.host = desc.host.host;
196-
}
197189
}
198190

199191
const state = opRevoke(desc);
@@ -213,10 +205,6 @@
213205
desc.path = pathFromURL(desc.path);
214206
} else if (desc.name === "run") {
215207
desc.command = pathFromURL(desc.command);
216-
} else if (desc.name === "net") {
217-
if (desc.host instanceof URL) {
218-
desc.host = desc.host.host;
219-
}
220208
}
221209

222210
const state = opRequest(desc);

0 commit comments

Comments
 (0)