Skip to content

Commit 3c562f6

Browse files
committed
Avoid creating an IndexError in lexer
1 parent 5183ae7 commit 3c562f6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

graphql/language/lexer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,14 @@ def position_after_whitespace(self, body: str, start_position: int) -> int:
234234
def read_comment(self, start: int, line: int, col: int, prev: Token) -> Token:
235235
"""Read a comment token from the source file."""
236236
body = self.source.body
237+
body_length = len(body)
238+
237239
position = start
238240
while True:
239241
position += 1
240-
try:
241-
char = body[position]
242-
except IndexError:
242+
if position > body_length:
243243
break
244+
char = body[position]
244245
if char < " " and char != "\t":
245246
break
246247
return Token(

0 commit comments

Comments
 (0)