Skip to content

Commit cc858c0

Browse files
authored
Merge pull request #456 from graphql-go/fix-panic-blockstring
language/lexer: fixes panic on empty blockstrings
2 parents c13c47a + 750c09f commit cc858c0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

language/lexer/lexer.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,13 @@ func blockStringValue(in string) string {
404404
}
405405

406406
// Remove leading blank lines.
407-
for {
408-
if isBlank := lineIsBlank(lines[0]); !isBlank {
409-
break
410-
}
407+
for len(lines) > 0 && lineIsBlank(lines[0]) {
411408
lines = lines[1:]
412409
}
413410

414411
// Remove trailing blank lines.
415-
for {
412+
for len(lines) > 0 && lineIsBlank(lines[len(lines)-1]) {
416413
i := len(lines) - 1
417-
if isBlank := lineIsBlank(lines[i]); !isBlank {
418-
break
419-
}
420414
lines = append(lines[:i], lines[i+1:]...)
421415
}
422416

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: BLOCK_STRING,
456+
Start: 0,
457+
End: 6,
458+
Value: "",
459+
},
460+
},
452461
{
453462
Body: `"""simple"""`,
454463
Expected: Token{

0 commit comments

Comments
 (0)