Skip to content

When MRB_UTF8_STRING is enabled, giving byte characters for String#index and String#split gives wrong results #6267

Description

@dearblue

I build with MRUBY_CONFIG=host-debug.
mruby revision is dcee404.

p "①②③④⑤\xe2".size
# => 6
p "①②③④⑤\xe2".unpack1("H*")
# => "e291a0e291a1e291a2e291a3e291a4e2"

p "①②③④⑤\xe2".index("\xa4")
# => 6
## Expected to nil
## mruby-3.3 returns nil

p "①②③④⑤\xe2".split("\xe2")
# => ["", "\x91\xa0", "\x91\xa1", "\x91\xa2", "\x91\xa3", "\x91\xa4"]
## Expected to ["①②③④⑤"]
## mruby-3.3 is also wrong

The String#split method uses the result of mrb_memsearch() directly.
The String#index method adjusts the result of mrb_memsearch() with byte2char(), but the result is wrong.

Just reporting it for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions