hasNewlineInStringLiteral returns true if s contains an actual newline character (\n) that appears inside a single-quoted GitHub Actions expression string literal. This is used to determine whether the YAML `if:` value needs special encoding to preserve the newline (e.g. for matching bot comments th
(s string)
| 464 | // This is used to determine whether the YAML `if:` value needs special encoding to |
| 465 | // preserve the newline (e.g. for matching bot comments that append metadata after a newline). |
| 466 | func hasNewlineInStringLiteral(s string) bool { |
| 467 | inString := false |
| 468 | i := 0 |
| 469 | for i < len(s) { |
| 470 | ch := s[i] |
| 471 | if ch == '\'' { |
| 472 | // Handle escaped single-quote inside a string: '' |
| 473 | if inString && i+1 < len(s) && s[i+1] == '\'' { |
| 474 | i += 2 // skip both quotes, stay in string |
| 475 | continue |
| 476 | } |
| 477 | inString = !inString |
| 478 | } else if ch == '\n' && inString { |
| 479 | return true |
| 480 | } |
| 481 | i++ |
| 482 | } |
| 483 | return false |
| 484 | } |
| 485 | |
| 486 | // escapeForYAMLDoubleQuoted escapes a string so it can be safely placed inside a YAML |
| 487 | // double-quoted scalar (i.e. wrapped with "..."). YAML double-quoted scalars interpret |
no outgoing calls