Skip to content

Fix parser error positions for newlines and multibyte characters - #1092

Merged
byroot merged 1 commit into
ruby:masterfrom
ydah:fix-parser-error-position
Oct 2, 2026
Merged

byroot merged 1 commit into
ruby:masterfrom
ydah:fix-parser-error-position

Conversation

@ydah

@ydah ydah commented Oct 2, 2026

Copy link
Copy Markdown
Member

An error on a newline is reported on the next line with column 0. Columns also count bytes instead of characters.

require "json"

JSON.parse("[1,\n\"ab\ncd\"]")
# Before: line 3 column 0
# After:  line 2 column 4

JSON.parse('["日本", @]')
# Before: line 1 column 12
# After:  line 1 column 8

Count newlines only before the error position and use Unicode codepoint counts for columns in both the C and Java parsers.

@byroot
byroot merged commit 590dd54 into ruby:master Oct 2, 2026
42 checks passed
@ydah
ydah deleted the fix-parser-error-position branch October 2, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants