Skip to content

Commit

Permalink
Fix #229 (#230)
Browse files Browse the repository at this point in the history
* account for newline characters in block str

* fix test and simplify block string line increment logic, fixes #229

* place block str test in correct section

Co-authored-by: Ahmad Moudani <[email protected]>
  • Loading branch information
zmay2030 and Ahmad Moudani authored Jul 20, 2022
1 parent 6498086 commit 6d5506b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ func (s *Lexer) readBlockString() (Token, *gqlerror.Error) {
// skip the close quote
s.end += 3
s.endRunes += 3

return t, err
}

Expand All @@ -456,6 +455,8 @@ func (s *Lexer) readBlockString() (Token, *gqlerror.Error) {
buf.WriteByte('\n')
s.end++
s.endRunes++
s.line++
s.lineStartRunes = s.endRunes
} else {
var char = rune(r)
var w = 1
Expand All @@ -467,6 +468,10 @@ func (s *Lexer) readBlockString() (Token, *gqlerror.Error) {
s.end += w
s.endRunes++
buf.WriteRune(char)
if r == '\n' {
s.line++
s.lineStartRunes = s.endRunes
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions lexer/lexer_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,26 @@ lexes block strings:
end: 36
value: "spans\n multiple\n lines"

- name: records correct line and column after block string
input: |
"""
some
description
""" foo
tokens:
-
kind: BLOCK_STRING
value: "some\ndescription"
-
kind: NAME
start: 27
end: 30
line: 6
column: 5
value: 'foo'

lex reports useful block string errors:
- name: unterminated string
input: '"""'
Expand Down
2 changes: 1 addition & 1 deletion parser/schema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,4 @@ fuzzer:
input: "\"\"\"\r"
error:
message: 'Unexpected <Invalid>'
locations: [{ line: 1, column: 5 }]
locations: [{ line: 2, column: 1 }]

0 comments on commit 6d5506b

Please sign in to comment.