MCPcopy Create free account
hub / github.com/cloudfoundry/java-buildpack / escapeValue

Function escapeValue

src/java/frameworks/java_opts.go:206–224  ·  view source on GitHub ↗

escapeValue escapes a string for shell safety using Ruby's escape_value method Ruby source: lib/java_buildpack/framework/java_opts.rb:61-67 str.gsub(%r{([^A-Za-z0-9_\-.,:/@\n$\\])}, '\\\\\\1').gsub(/\n/, "'\n'") Safe chars (not escaped): A-Za-z0-9_-.,:/@$\ All other chars are backslash-escaped,

(value string)

Source from the content-addressed store, hash-verified

204// Safe chars (not escaped): A-Za-z0-9_-.,:/@$\
205// All other chars are backslash-escaped, including: = ( ) [ ] { } ; & | space % etc.
206func escapeValue(value string) string {
207 if value == "" {
208 return "''"
209 }
210
211 var result strings.Builder
212 for _, ch := range value {
213 if ch == '\n' {
214 result.WriteString("'\n'") // Special newline handling
215 continue
216 }
217
218 if !isRubySafeChar(ch) {
219 result.WriteRune('\\')
220 }
221 result.WriteRune(ch)
222 }
223 return result.String()
224}
225
226// isRubySafeChar checks if a character is in Ruby's safe set: A-Za-z0-9_-.,:/@\n$\
227// Note: '=' is NOT safe and will be escaped

Callers 1

rubyStyleEscapeFunction · 0.85

Calls 2

isRubySafeCharFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected