From 10c28942dc37dab07f5f81a77dbad950c9ea1827 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Thu, 2 Jul 2026 02:28:09 -0700 Subject: [PATCH] fix(dsl): avoid panic on unterminated string escape at EOF Signed-off-by: Sai Asish Y --- pkg/dsl/lexer/lexer.go | 5 +++++ pkg/dsl/lexer/lexer_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/dsl/lexer/lexer.go b/pkg/dsl/lexer/lexer.go index 5a8b38fe4..055a9eed8 100644 --- a/pkg/dsl/lexer/lexer.go +++ b/pkg/dsl/lexer/lexer.go @@ -212,6 +212,11 @@ func (l *Lexer) lexString() string { if l.ch == '\\' { str += l.input[position:l.position] l.readChar() // Skip the backslash + if l.ch == 0 { + // Backslash at end of input (unterminated escape); stop before + // position runs past the input. + break + } switch l.ch { case 'n': str += "\n" diff --git a/pkg/dsl/lexer/lexer_test.go b/pkg/dsl/lexer/lexer_test.go index 969054738..8fc3ad6b6 100644 --- a/pkg/dsl/lexer/lexer_test.go +++ b/pkg/dsl/lexer/lexer_test.go @@ -1189,4 +1189,13 @@ rule test_rule(created_at time, started_at time) { Expect(hasBoolean).Should(BeTrue()) Expect(hasComparison).Should(BeTrue()) }) + + It("Unterminated string ending in a backslash does not panic", func() { + // A quote followed by a trailing backslash reaches EOF mid-escape. + l := NewLexer("\"\\") + + var tok token.Token + Expect(func() { tok = l.NextToken() }).ShouldNot(Panic()) + Expect(tok.Type).Should(BeEquivalentTo(token.STRING)) + }) })