Skip to content

Commit 8c0f84d

Browse files
committed
Amend assert in pm_utf_8_codepoint(), n=0 is fine
This assert used to trip in the included test: ``` ./miniruby --parser=prism -e ' "%W"\u" ' ```
1 parent 73b4b28 commit 8c0f84d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/encoding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,7 @@ static const uint8_t pm_utf_8_dfa[] = {
22522252
*/
22532253
static pm_unicode_codepoint_t
22542254
pm_utf_8_codepoint(const uint8_t *b, ptrdiff_t n, size_t *width) {
2255-
assert(n >= 1);
2255+
assert(n >= 0);
22562256
size_t maximum = (size_t) n;
22572257

22582258
uint32_t codepoint;

test/prism/format_errors_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ def test_format_errors
1212
| ^ unexpected '<', ignoring it
1313
| ^ unexpected '>', ignoring it
1414
ERROR
15+
16+
assert_equal <<~'ERROR', Debug.format_errors('"%W"\u"', false)
17+
> 1 | "%W"\u"
18+
| ^ expected a newline or semicolon after the statement
19+
| ^ invalid token
20+
| ^ expected a closing delimiter for the string literal
21+
ERROR
1522
end
1623
end
1724
end

0 commit comments

Comments
 (0)