Preserve inline YAML document starts in aggregate reports
This commit is contained in:
17
show.go
17
show.go
@@ -107,7 +107,7 @@ func hasYAMLDirective(native []byte) bool {
|
||||
lines := bytes.Split(native, []byte("\n"))
|
||||
for _, line := range lines {
|
||||
trimmed := bytes.TrimSpace(line)
|
||||
if bytes.Equal(trimmed, []byte("---")) || bytes.HasPrefix(trimmed, []byte("--- #")) {
|
||||
if isYAMLDocumentStart(string(trimmed)) {
|
||||
return false
|
||||
}
|
||||
if bytes.HasPrefix(trimmed, []byte("%YAML ")) || bytes.HasPrefix(trimmed, []byte("%TAG ")) {
|
||||
@@ -135,8 +135,17 @@ func frameEffectiveYAML(scope string, native []byte) []byte {
|
||||
hasDirective := false
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimSpace(string(line))
|
||||
if trimmed == "---" || strings.HasPrefix(trimmed, "--- #") {
|
||||
if isYAMLDocumentStart(trimmed) {
|
||||
out := make([]byte, 0, len(native)+len(comment))
|
||||
// Inline content may be a block scalar; place the label before
|
||||
// its marker rather than interrupting the native value.
|
||||
content := strings.TrimSpace(strings.TrimPrefix(trimmed, "---"))
|
||||
if content != "" && !strings.HasPrefix(content, "#") {
|
||||
out = append(out, native[:position]...)
|
||||
out = append(out, comment...)
|
||||
out = append(out, native[position:]...)
|
||||
return out
|
||||
}
|
||||
out = append(out, native[:position+len(line)]...)
|
||||
if len(line) > 0 && line[len(line)-1] != '\n' {
|
||||
out = append(out, '\n')
|
||||
@@ -175,3 +184,7 @@ func showFailure(cause error, diagnostics []Diagnostic, reportStarted bool) Outc
|
||||
outcome.ReportIncomplete = reportStarted
|
||||
return outcome
|
||||
}
|
||||
|
||||
func isYAMLDocumentStart(line string) bool {
|
||||
return strings.HasPrefix(line, "---") && (len(line) == 3 || line[3] == ' ' || line[3] == '\t')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user