From bd61a52463dab8850a5204bb58f6bfc094d6f1be Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Fri, 23 Oct 2026 22:33:53 +1100 Subject: [PATCH] colour: treat ? as a YAML key indicator only before space or EOL --- colour/colour_test.go | 2 ++ colour/yaml.go | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/colour/colour_test.go b/colour/colour_test.go index 745eb14..c9de789 100644 --- a/colour/colour_test.go +++ b/colour/colour_test.go @@ -172,6 +172,8 @@ func TestYAMLEdges(t *testing.T) { " - pem: |\n -----BEGIN CERTIFICATE-----\n MIIB\n ttl: 768h\n n: 1\n", "w: one two\n\n 42\n# c\nn: 1\n": "w: one two\n\n 42\n# c\nn: 1\n", "q: 'it''s\n ok: y' # c\n": "q: 'it''s\n ok: y' # c\n", + "?q: ?v\n?n:\n a: 1\n b: |\n x\nd: 2\n": "?q: ?v\n?n:\n a: 1\n" + + " b: |\n x\nd: 2\n", } for in, want := range cases { if got := render(t, yamlF, in); got != want { diff --git a/colour/yaml.go b/colour/yaml.go index 03404e0..04f6b6f 100644 --- a/colour/yaml.go +++ b/colour/yaml.go @@ -129,10 +129,12 @@ func yamlNode(out *bytes.Buffer, s string) (int, byte) { // not a key/value pair. func keyEnd(s string) int { end := 0 - switch s[0] { - case '"', '\'': + switch { + case s[0] == '"' || s[0] == '\'': end = quoteEnd(s) - case '[', '{', '&', '*', '!', '|', '>', '?', '%', '@', '`': + case s[0] == '?' && (len(s) == 1 || s[1] == ' '): + return 0 + case strings.IndexByte("[{&*!|>%@`", s[0]) >= 0: return 0 default: for i := 0; i < len(s); i++ {