Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphemeCursor::is_boundary returns wrong value inside emoji when chunked one codepoint at a time #139

Open
pfgithub opened this issue Sep 12, 2024 · 1 comment

Comments

@pfgithub
Copy link

The first time, the chunk containing both [man] and [zwj] is passed into provideContext at the same time. This works and returns the expected result. The second time, the chunk containing [zwj] is provided first, and then the chunk containing [man] is provided. This doesn't work and returns 'true' as if there is a boundary in the middle of an emoji.

#[cfg(test)]
mod tests {
    use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete::*};

    const family_emoji: &str = "A\u{1F468}\u{200D}\u{1F469}\u{1F467}B";
    // "A👨‍👩‍👧‍👧B" : [0: A] [1: MAN] [5: Zero Width Joiner] [8: WOMAN] [12: GIRL] [16: B]

    #[test]
    fn passes() {
        let mut cursor = GraphemeCursor::new(8, family_emoji.len(), true);
        assert_eq!(cursor.is_boundary(&family_emoji[8..], 8), Err(PreContext(8)));
        cursor.provide_context(&family_emoji[1..8], 1);
        assert_eq!(cursor.is_boundary(&family_emoji[8..], 8), Ok(false));
    }

    #[test]
    fn fails() {
        let mut cursor = GraphemeCursor::new(8, family_emoji.len(), true);
        assert_eq!(cursor.is_boundary(&family_emoji[8..], 8), Err(PreContext(8)));
        cursor.provide_context(&family_emoji[5..8], 5);
        assert_eq!(cursor.is_boundary(&family_emoji[8..], 8), Err(PreContext(5)));
        cursor.provide_context(&family_emoji[1..5], 1);
        assert_eq!(cursor.is_boundary(&family_emoji[8..], 8), Ok(false));
    }
}

Potentially related: #118

@Manishearth
Copy link
Member

Yep, the chunked API is buggy. I don't have time to investigate/fix this but I appreciate others trying. We should also try to run it with the tests much more, potentially fuzzed.

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

No branches or pull requests

2 participants