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)
| 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. |
| 491 | func 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 | } |