MCPcopy
hub / github.com/wavetermdev/waveterm / HardQuote

Function HardQuote

pkg/util/shellutil/shellquote.go:24–51  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

22}
23
24func HardQuote(s string) string {
25 if s == "" {
26 return "\"\""
27 }
28
29 if safePattern.MatchString(s) {
30 return s
31 }
32
33 if !checkQuoteSize(s) {
34 return ""
35 }
36
37 buf := make([]byte, 0, len(s)+5)
38 buf = append(buf, '"')
39
40 for i := 0; i < len(s); i++ {
41 switch s[i] {
42 case '"', '\\', '$', '`':
43 buf = append(buf, '\\', s[i])
44 default:
45 buf = append(buf, s[i])
46 }
47 }
48
49 buf = append(buf, '"')
50 return string(buf)
51}
52
53// does not encode newlines or backticks
54func HardQuoteFish(s string) string {

Callers 6

StartConnServerMethod · 0.92
StartConnServerMethod · 0.92
BuildShellCommandFunction · 0.92
InitRcFilesFunction · 0.85
TestQuoteFunction · 0.85
encodeEnvVarsForBashFunction · 0.85

Calls 1

checkQuoteSizeFunction · 0.85

Tested by 1

TestQuoteFunction · 0.68