MCPcopy Index your code
hub / github.com/restic/restic / SplitShellStrings

Function SplitShellStrings

internal/backend/shell_split.go:45–76  ·  view source on GitHub ↗

SplitShellStrings returns the list of shell strings from a shell command string.

(data string)

Source from the content-addressed store, hash-verified

43
44// SplitShellStrings returns the list of shell strings from a shell command string.
45func SplitShellStrings(data string) (strs []string, err error) {
46 s := &shellSplitter{}
47
48 // derived from strings.SplitFunc
49 fieldStart := -1 // Set to -1 when looking for start of field.
50 for i, r := range data {
51 if s.isSplitChar(r) {
52 if fieldStart >= 0 {
53 strs = append(strs, data[fieldStart:i])
54 fieldStart = -1
55 }
56 } else if fieldStart == -1 {
57 fieldStart = i
58 }
59 }
60 if fieldStart >= 0 { // Last field might end at EOF.
61 strs = append(strs, data[fieldStart:])
62 }
63
64 switch s.quote {
65 case '\'':
66 return nil, errors.New("single-quoted string not terminated")
67 case '"':
68 return nil, errors.New("double-quoted string not terminated")
69 }
70
71 if len(strs) == 0 {
72 return nil, errors.New("command string is empty")
73 }
74
75 return strs, nil
76}

Callers 5

newBackendFunction · 0.92
buildSSHCommandFunction · 0.92
resolvePasswordFunction · 0.92
TestShellSplitterFunction · 0.85
TestShellSplitterInvalidFunction · 0.85

Calls 1

isSplitCharMethod · 0.95

Tested by 2

TestShellSplitterFunction · 0.68
TestShellSplitterInvalidFunction · 0.68