Skip to content

agent template format fails when followed by quoted template snippet #45

@efd6

Description

@efd6

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 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions