Skip to content

Commit

Permalink
Merge pull request #456 from graphql-go/fix-panic-blockstring
Browse files Browse the repository at this point in the history
language/lexer: fixes panic on empty blockstrings
  • Loading branch information
chris-ramon authored Mar 12, 2019
2 parents c13c47a + 750c09f commit cc858c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 2 additions & 8 deletions language/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,13 @@ func blockStringValue(in string) string {
}

// Remove leading blank lines.
for {
if isBlank := lineIsBlank(lines[0]); !isBlank {
break
}
for len(lines) > 0 && lineIsBlank(lines[0]) {
lines = lines[1:]
}

// Remove trailing blank lines.
for {
for len(lines) > 0 && lineIsBlank(lines[len(lines)-1]) {
i := len(lines) - 1
if isBlank := lineIsBlank(lines[i]); !isBlank {
break
}
lines = append(lines[:i], lines[i+1:]...)
}

Expand Down
9 changes: 9 additions & 0 deletions language/lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,15 @@ func TestLexer_ReportsUsefulStringErrors(t *testing.T) {

func TestLexer_LexesBlockStrings(t *testing.T) {
tests := []Test{
{
Body: `""""""`,
Expected: Token{
Kind: BLOCK_STRING,
Start: 0,
End: 6,
Value: "",
},
},
{
Body: `"""simple"""`,
Expected: Token{
Expand Down

0 comments on commit cc858c0

Please sign in to comment.