fix(action): block scalar supprot for contiguous separators

Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
pull/31978/head
Brandt Keller 2 weeks ago
parent 7e149c7229
commit dbd3d55fa7
No known key found for this signature in database

@ -162,8 +162,15 @@ func fixDocSeparators(content string) string {
}
// "---" must be at the start of a line: either idx==0 or preceded by '\n'.
if idx > 0 && remaining[idx-1] != '\n' {
b.WriteString(remaining[:idx+3])
remaining = remaining[idx+3:]
// Skip past all contiguous dashes to avoid re-examining
// interior dashes of a long sequence (e.g. "--------------------")
// as a new "---" at position 0 of the remaining buffer.
end := idx + 3
for end < len(remaining) && remaining[end] == '-' {
end++
}
b.WriteString(remaining[:end])
remaining = remaining[end:]
continue
}
b.WriteString(remaining[:idx+3])

@ -484,6 +484,11 @@ func TestFixDocSeparators(t *testing.T) {
input: "----more\napiVersion: v1\n",
expected: "---\n-more\napiVersion: v1\n",
},
{
name: "long dashes in block scalar are not separators",
input: "apiVersion: v1\nkind: Job\nspec:\n containers:\n - command:\n - |\n echo --------------------\n echo done\n",
expected: "apiVersion: v1\nkind: Job\nspec:\n containers:\n - command:\n - |\n echo --------------------\n echo done\n",
},
}
for _, tt := range tests {

Loading…
Cancel
Save