Commit fc60d48
committed
Stop the lexer reading past the end of a byte_range
`rbs_next_char` ends the input when `byte_pos == end_pos`. `rbs_skip`
advances by a whole character, so a multibyte character starting before
`end_pos` and ending after it steps over the boundary and equality never
holds again — the lexer then reads to the end of the string.
The realistic way to land inside a character is to pass a character
offset where a byte offset is expected, the mistake #2945 fixed in
`parse_inline_*_annotation`. `"日本語"` is 5 characters but 11 bytes, so
offset 5 falls inside `本`:
Parser.parse_type('"日本語" | Integer', byte_range: 0...5)
#=> Types::Union spanning the whole input, rather than an error
`require_eof: true` does not catch it, because the lexer really is at
EOF by then. It needs a character to straddle the boundary, so
ASCII-only input never hits it.
Compare with `>=` so stepping over the boundary still ends the input.1 parent 654954a commit fc60d48
2 files changed
Lines changed: 28 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
| |||
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
136 | | - | |
| 138 | + | |
| 139 | + | |
137 | 140 | | |
138 | 141 | | |
139 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1074 | 1074 | | |
1075 | 1075 | | |
1076 | 1076 | | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
1077 | 1100 | | |
0 commit comments