MCPcopy Create free account
hub / github.com/github/gh-aw / escapeForYAMLDoubleQuoted

Function escapeForYAMLDoubleQuoted

pkg/workflow/expression_parser.go:491–510  ·  view source on GitHub ↗

escapeForYAMLDoubleQuoted escapes a string so it can be safely placed inside a YAML double-quoted scalar (i.e. wrapped with "..."). YAML double-quoted scalars interpret \n, \r, \t, \\ and \" escape sequences, so we convert the corresponding actual characters to their two-character backslash represe

(s string)

Source from the content-addressed store, hash-verified

489// to their two-character backslash representations. After YAML parsing, the values are
490// restored, so GitHub Actions receives the expression with the real characters intact.
491func escapeForYAMLDoubleQuoted(s string) string {
492 var b strings.Builder
493 for i := range len(s) {
494 switch s[i] {
495 case '\\':
496 b.WriteString(`\\`)
497 case '"':
498 b.WriteString(`\"`)
499 case '\n':
500 b.WriteString(`\n`)
501 case '\r':
502 b.WriteString(`\r`)
503 case '\t':
504 b.WriteString(`\t`)
505 default:
506 b.WriteByte(s[i])
507 }
508 }
509 return b.String()
510}

Callers 2

renderJobToMethod · 0.85

Calls 1

StringMethod · 0.45

Tested by 1