Skip to content

Commit 63adf01

Browse files
committed
fix panic when a blockstring has only 1 line and blank
1 parent 21fe71d commit 63adf01

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

language/lexer/lexer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ func blockStringValue(in string) string {
427427

428428
// Remove leading blank lines.
429429
for {
430+
if len(lines) == 1 {
431+
break
432+
}
430433
if isBlank := lineIsBlank(lines[0]); !isBlank {
431434
break
432435
}

language/lexer/lexer_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,15 @@ func TestLexer_ReportsUsefulStringErrors(t *testing.T) {
449449

450450
func TestLexer_LexesBlockStrings(t *testing.T) {
451451
tests := []Test{
452+
{
453+
Body: `""""""`,
454+
Expected: Token{
455+
Kind: TokenKind[BLOCK_STRING],
456+
Start: 0,
457+
End: 6,
458+
Value: "",
459+
},
460+
},
452461
{
453462
Body: `"""simple"""`,
454463
Expected: Token{

0 commit comments

Comments
 (0)