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

Function hasNewlineInStringLiteral

pkg/workflow/expression_parser.go:466–484  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
466func 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

Callers 2

renderJobToMethod · 0.85

Calls

no outgoing calls

Tested by 1