mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
[ruby/prism] Avoid breaking code units offset on binary encoding
25a4cf6794
Co-authored-by: Kevin Newton <kddnewton@users.noreply.github.com>
This commit is contained in:
parent
615a087216
commit
e50754fcfa
2 changed files with 20 additions and 1 deletions
|
@ -90,7 +90,7 @@ module Prism
|
|||
# concept of code units that differs from the number of characters in other
|
||||
# encodings, it is not captured here.
|
||||
def code_units_offset(byte_offset, encoding)
|
||||
byteslice = (source.byteslice(0, byte_offset) or raise).encode(encoding)
|
||||
byteslice = (source.byteslice(0, byte_offset) or raise).encode(encoding, invalid: :replace, undef: :replace)
|
||||
|
||||
if encoding == Encoding::UTF_16LE || encoding == Encoding::UTF_16BE
|
||||
byteslice.bytesize / 2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue