Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Only set allow net flag for deno serve if not already allowed all #25743

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4738,7 +4738,10 @@ fn serve_parse(
format!("{host}:{port}")
}])?;
match &mut flags.permissions.allow_net {
None => flags.permissions.allow_net = Some(allowed),
None if !flags.permissions.allow_all => {
flags.permissions.allow_net = Some(allowed)
}
None => {}
Some(v) => {
if !v.is_empty() {
v.extend(allowed);
Expand Down Expand Up @@ -10747,6 +10750,31 @@ mod tests {
);
}

#[test]
fn serve_with_allow_all() {
let r = flags_from_vec(svec!["deno", "serve", "--allow-all", "./main.ts"]);
let flags = r.unwrap();
assert_eq!(
&flags,
&Flags {
subcommand: DenoSubcommand::Serve(ServeFlags::new_default(
"./main.ts".into(),
8000,
"0.0.0.0"
)),
permissions: PermissionFlags {
allow_all: true,
allow_net: None,
..Default::default()
},
code_cache_enabled: true,
..Default::default()
}
);
// just make sure this doesn't panic
let _ = flags.permissions.to_options();
}

#[test]
fn escape_and_split_commas_test() {
assert_eq!(escape_and_split_commas("foo".to_string()).unwrap(), ["foo"]);
Expand Down