Skip to content

Commit

Permalink
feat: execute中命令不能有反斜杠
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnotech committed Feb 22, 2024
1 parent c547fb9 commit c8e905d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/nep/definition/4-steps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import { Tag } from "../../components/tag.tsx"
* 类型:`String`
* 示例:`command = "./installer.exe /S"`
* 校验规则:
* 不得出现反斜杠(\),需使用正斜杠代替
* 符合 POSIX 命令格式
* 不得出现绝对路径(使用[内置变量](/nep/workflow/2-context.html#内置变量))
#### pwd
Expand Down
6 changes: 6 additions & 0 deletions src/types/steps/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::time::Instant;
pub struct StepExecute {
/// 需要执行的命令,使用终端为 cmd。
//# `command = "./installer.exe /S"`
//@ 不得出现反斜杠(\),需使用正斜杠代替
//@ 符合 POSIX 命令格式
//@ 不得出现绝对路径(使用[内置变量](/nep/workflow/2-context.html#内置变量))
pub command: String,
Expand Down Expand Up @@ -164,6 +165,11 @@ impl Interpretable for StepExecute {

impl Verifiable for StepExecute {
fn verify_self(&self, _: &String) -> Result<()> {
// 不得出现反斜杠
if self.command.contains("\\") {
return Err(anyhow!("Error(Execute):Backslash (\\) in '{cmd}' is not allowed, use forward slash (/) instead",cmd=&self.command));
}

// 校验 pwd 为合法路径
if let Some(pwd) = &self.pwd {
values_validator_path(pwd).map_err(|e| {
Expand Down

0 comments on commit c8e905d

Please sign in to comment.