Skip to content

longest_common_prefix could fail with non-ascii codepoints #14

@Boscop

Description

@Boscop

longest_common_prefix finds the byte index of the longest common byte prefix:
https://docs.rs/commands/0.0.5/src/commands/util.rs.html#23-39

But slicing a string at a byte index that's not a char index (i.e. is in the middle of a utf-8 codepoint) is invalid:
https://stackoverflow.com/questions/51982999/slice-a-string-containing-unicode-chars
The function would panic if two of the given strings contain codepoints that start with the same byte but differ after that.
Using char_indices would fix this :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions