(command string)
| 19 | ) |
| 20 | |
| 21 | func ValidateSedCommand(command string) SedValidationResult { |
| 22 | if strings.TrimSpace(command) == "" { |
| 23 | return SedValidationResult{Safe: false, Reason: "Empty command"} |
| 24 | } |
| 25 | expressions := extractSedExpressions(command) |
| 26 | if len(expressions) == 0 { |
| 27 | return SedValidationResult{Safe: false, Reason: "Could not parse sed expression"} |
| 28 | } |
| 29 | hasIFlag := hasInplaceFlag(command) |
| 30 | for _, expr := range expressions { |
| 31 | result := validateSingleSedExpression(expr, hasIFlag) |
| 32 | if !result.Safe { |
| 33 | return result |
| 34 | } |
| 35 | } |
| 36 | files := []string{} |
| 37 | if hasIFlag { |
| 38 | files = extractSedFileArgs(command) |
| 39 | } |
| 40 | return SedValidationResult{ |
| 41 | Safe: true, Reason: "Safe sed operation", |
| 42 | NeedsFilePermission: hasIFlag, FilePaths: files, |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | func extractSedExpressions(command string) []string { |
| 47 | var expressions []string |
nothing calls this directly
no test coverage detected