yamlStringValue returns a YAML-safe representation of a string value. If the value starts with a YAML flow indicator ('{' or '[') or other characters that would cause it to be misinterpreted by YAML parsers, it wraps the value in single quotes. Any embedded single quotes are escaped by doubling them
(value string)
| 336 | // that would cause it to be misinterpreted by YAML parsers, it wraps the value |
| 337 | // in single quotes. Any embedded single quotes are escaped by doubling them (' becomes ”). |
| 338 | func yamlStringValue(value string) string { |
| 339 | if value == "" { |
| 340 | return value |
| 341 | } |
| 342 | if quoted := quoteYAMLValueContainingColonSpace(value); quoted != value { |
| 343 | return quoted |
| 344 | } |
| 345 | // Values starting with YAML flow indicators need quoting to be treated as strings. |
| 346 | // '{' would be parsed as a YAML flow mapping, '[' as a YAML flow sequence. |
| 347 | first := value[0] |
| 348 | if first != '{' && first != '[' { |
| 349 | return value |
| 350 | } |
| 351 | // Single-quote the value, escaping any embedded single quotes by doubling them. |
| 352 | return "'" + strings.ReplaceAll(value, "'", "''") + "'" |
| 353 | } |
| 354 | |
| 355 | // FilterEnvForSecrets filters environment variables to only include allowed secrets. |
| 356 | // This is a security measure to ensure that only necessary secrets are passed to the execution step. |