restrict plugin file name (#6479)

This commit is contained in:
WindSoilder 2022-09-05 07:00:20 +08:00 committed by GitHub
parent 65327e0e7e
commit a6ba58ec41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3197,13 +3197,28 @@ pub fn parse_register(
nu_engine::env::env_to_strings(working_set.permanent_state, &stack).unwrap_or_default();
let error = match signature {
Some(signature) => arguments.and_then(|(path, encoding)| {
// restrict plugin file name starts with `nu_plugin_`
let f_name = path
.file_name()
.map(|s| s.to_string_lossy().starts_with("nu_plugin_"));
if let Some(true) = f_name {
signature.map(|signature| {
let plugin_decl = PluginDeclaration::new(path, signature, encoding, shell);
working_set.add_decl(Box::new(plugin_decl));
working_set.mark_plugins_file_dirty();
})
} else {
Ok(())
}
}),
None => arguments.and_then(|(path, encoding)| {
// restrict plugin file name starts with `nu_plugin_`
let f_name = path
.file_name()
.map(|s| s.to_string_lossy().starts_with("nu_plugin_"));
if let Some(true) = f_name {
get_signature(path.as_path(), &encoding, &shell, &current_envs)
.map_err(|err| {
ParseError::LabeledError(
@ -3228,6 +3243,9 @@ pub fn parse_register(
working_set.mark_plugins_file_dirty();
})
} else {
Ok(())
}
}),
}
.err();