Skip to content

Commit 7b87f2a

Browse files
committed
Fix lexer issue with empty string (#18)
1 parent 20a1a69 commit 7b87f2a

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ a query language for APIs created by Facebook.
1313
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
1414

1515
The current version 1.0.1 of GraphQL-core-next is up-to-date with GraphQL.js version
16-
14.0.2. All parts of the API are covered by an extensive test suite of currently 1657
16+
14.0.2. All parts of the API are covered by an extensive test suite of currently 1659
1717
unit tests.
1818

1919

graphql/language/lexer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def __init__(
5252
self.kind = kind
5353
self.start, self.end = start, end
5454
self.line, self.column = line, column
55-
self.prev: Optional[Token] = prev or None
55+
self.prev: Optional[Token] = prev
5656
self.next: Optional[Token] = None
57-
self.value: Optional[str] = value or None
57+
self.value: Optional[str] = value
5858

5959
def __repr__(self):
6060
return "<Token {} at {}-{} ({}/{})>".format(

tests/language/test_lexer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ def updates_column_numbers_in_error_for_file_context():
9595
"""
9696
)
9797

98+
# noinspection PyArgumentEqualDefault
99+
def lexes_empty_string():
100+
token = lex_one('""')
101+
assert token == Token(TokenKind.STRING, 0, 2, 1, 1, None, "")
102+
assert token.value == ""
103+
98104
# noinspection PyArgumentEqualDefault
99105
def lexes_strings():
100106
assert lex_one('"simple"') == Token(

tests/language/test_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@ def parses_null_value():
388388
assert isinstance(result, NullValueNode)
389389
assert result.loc == (0, 4)
390390

391+
def parses_empty_strings():
392+
result = parse_value('""')
393+
assert isinstance(result, StringValueNode)
394+
assert result.value == ""
395+
assert result.loc == (0, 2)
396+
391397
def parses_list_values():
392398
result = parse_value('[123 "abc"]')
393399
assert isinstance(result, ListValueNode)

0 commit comments

Comments
 (0)