agent template format fails when followed by quoted template snippet
- Dominant language
- Go
- Stars
- 1
- Forks
- 4
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 3
Description
The following (minimised) test fails:
```
celfmt -agent -i src.cel
! stderr .
cmp stdout want.txt
-- src.cel --
program: |-
{}
fields: "{{toxic_when_quoted}}"
-- want.txt --
program: |-
{}
fields: "{{toxic_when_quoted}}"
```
```
--- FAIL: TestScripts (0.00s)
--- FAIL: TestScripts/bug (0.05s)
testscript.go:584: > celfmt -agent -i src.cel
[stderr]
2025/07/16 14:48:21 yaml: line 3: found unexpected end of stream
[exit status 1]
FAIL: testdata/bug.txt:1: unexpected command failure
```
If the `"{{toxic_when_quoted}}"` is replaced with `{{toxic_when_quoted}}` it does not fail. Nor does it fail if the `fields` object is placed above `program`.
This happens in [`*visitor.VisitContent`](https://github.com/elastic/celfmt/blob/37b2f2f9279009b3f511b9b022f1382ea30a5056/cmd/celfmt/main.go#L128) because the `s.Value` ends at the `"` prior to the template snippet because we are assuming (incorrectly) that the remainder of the text of the value is valid YAML (which it is not in this case).
I'm not sure what the approach to fixing this is. The work around is to not make source that looks like this.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.