Skip to content

Irregal capture after recursive match#48

Description

@osamutake

Thank you very much for maintaining the excellent library.

I found the latest version of Onigmo suffers from the following incorrect behavior when used with a recursive expression.

/\(((?:[^(]|\g<0>)*)\)/ matches "(abc)(abc)" => OK 馃挌
matches[0] == (0, 5) corresponding to "(abc)" => OK 馃挌
matches[1] == (6, 4) corresponding to a string with negative length => NG 馃挃

/\(((?:[^()]|\g<0>)*)\)/ matches "((abc)(abc))" => OK 馃挌
matches[0] == (0, 12) corresponding to "((abc)(abc))" => OK 馃挌
matches[1] == (7, 11) corresponding to "abc)" => NG 馃挃

It seems that matches[].rm_so refers to the last capture while matches[].rm_eo refers to to the top level capture. I believe the users will be happier if both of them refers to the top level capture. When tested in ruby, the former example returns an invalid string for $2 that causes ArgumentError when given to a function as described at ruby/姝h琛ㄧ従.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions