MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / ValidateSedCommand

Function ValidateSedCommand

tools/bash/sed_validation.go:21–44  ·  view source on GitHub ↗
(command string)

Source from the content-addressed store, hash-verified

19)
20
21func 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
46func extractSedExpressions(command string) []string {
47 var expressions []string

Callers

nothing calls this directly

Calls 4

extractSedExpressionsFunction · 0.85
hasInplaceFlagFunction · 0.85
extractSedFileArgsFunction · 0.85

Tested by

no test coverage detected