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::next_boundary() returns incorrect boundary when chunk starts with ZWJ #118

Open
sarah-quinones opened this issue Mar 13, 2023 · 1 comment

Comments

@sarah-quinones
Copy link

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8fe7258129406b137529559157edd542

use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};

#[test]
fn test_graphemes_chunked() {
    use GraphemeIncomplete::*;

    let chunk0 = "👩"; // 4 bytes
    let chunk1 = "\u{200d}🔬"; // 3 bytes + 4 bytes
    let full = &(chunk0.to_string() + chunk1); // 👩‍🔬

    let mut cur = GraphemeCursor::new(0, full.len(), true);
    assert_eq!(cur.next_boundary(chunk0, 0), Err(NextChunk));
    match cur.next_boundary(chunk1, chunk0.len()) {
        Ok(res) => assert_eq!(res, Some(11)),
        Err(PreContext(_)) => {
            cur.provide_context(chunk0, 0);
            assert_eq!(cur.next_boundary(chunk1, chunk0.len()), Ok(Some(11)));
        }
        _ => unreachable!(),
    }
}

the last assert panics and says that it expected Ok(Some(7)), when instead it should be Ok(Some(11))

@Manishearth
Copy link
Member

Potentially related: #115

The chunking stuff is buggy around some states. I don't have the time to investigate this right now but happy to help someone who wants to.

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