Skip to content

Commit da6eb6f

Browse files
takeshi.nakatasaranrapjs
authored andcommitted
modify make token by byte position, not rune position at readName
1 parent d4506c6 commit da6eb6f

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

language/lexer/lexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func readName(source *source.Source, position, runePosition int) Token {
129129
break
130130
}
131131
}
132-
return makeToken(NAME, runePosition, endRune, string(body[position:endByte]))
132+
return makeToken(NAME, position, endByte, string(body[position:endByte]))
133133
}
134134

135135
// Reads a number token from the source file, either a float

language/lexer/lexer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ func TestLexer_AcceptsBOMHeader(t *testing.T) {
9191
Body: "\uFEFF foo",
9292
Expected: Token{
9393
Kind: NAME,
94-
Start: 2,
95-
End: 5,
94+
Start: 4,
95+
End: 7,
9696
Value: "foo",
9797
},
9898
},

language/parser/parser_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,19 @@ func TestParsesEnumValueDefinitionWithDescription(t *testing.T) {
490490
}
491491
}
492492

493+
func TestParsesTypeDefinitionWithMultiByteCharactersComment_UnicodeText(t *testing.T) {
494+
source := `
495+
# This comment has a фы世界 character.
496+
type Foo implements Bar {
497+
foo: String!
498+
}
499+
`
500+
_, err := Parse(ParseParams{Source: source})
501+
if err != nil {
502+
t.Fatalf("unexpected error: %v", err)
503+
}
504+
}
505+
493506
func TestDefinitionsWithDescriptions(t *testing.T) {
494507
testCases := []struct {
495508
name string

0 commit comments

Comments
 (0)