Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

language/lexer: fixes panic on empty blockstrings #456

Merged
merged 5 commits into from
Mar 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
language/lexer: code clean-up
  • Loading branch information
chris-ramon committed Mar 10, 2019
commit 750c09f8aed34ccf2cacedccb4cf2a68ece8e317
16 changes: 2 additions & 14 deletions language/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,25 +404,13 @@ func blockStringValue(in string) string {
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidates the following couple of loops to remove blank lines, follows the graphql-js reference implementation:

  // Remove leading and trailing blank lines.
  while (lines.length > 0 && isBlank(lines[0])) {
    lines.shift();
  }
  while (lines.length > 0 && isBlank(lines[lines.length - 1])) {
    lines.pop();
  }

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
}
if len(lines) == 1 {
break
}
lines = append(lines[:i], lines[i+1:]...)
}

Expand Down