Closed Bug 1890007 Opened 2 years ago Closed 2 years ago

Intl.Segmenter incorrectly breaks up some flag emoji (grapheme clusters)

Categories

(Core :: JavaScript: Internationalization API, defect, P3)

Firefox 126
defect

Tracking

()

RESOLVED DUPLICATE of bug 1899411

People

(Reporter: nick.gard.dev, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0

Steps to reproduce:

const segmenter = new Intl.Segmenter({ granularity: "word" });
Array.from(segmenter.segment('🇺🇸🏴󠁧󠁢󠁥󠁮󠁧󠁿')).map(
({ segment }) => segment
);

Actual results:

It resulted in

[ "🇺", "🇸", "🏴󠁧󠁢󠁥󠁮󠁧󠁿" ]

Expected results:

It should have resulted in

['🇺🇸', '🏴󠁧󠁢󠁥󠁮󠁧󠁿']

(In reply to nick.gard.dev from comment #0)
Small mistake in the code pasted above. It does not require the { granularity: 'word' } option.

const segmenter = new Intl.Segmenter();
Array.from(segmenter.segment('🇺🇸🏴󠁧󠁢󠁥󠁮󠁧󠁿')).map(
({ segment }) => segment
);

The Bugbug bot thinks this bug should belong to the 'Core::Internationalization' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Internationalization
Product: Firefox → Core

Thanks for the report! I've forwarded this issue to https://github.com/unicode-org/icu4x/issues/4780.

Component: Internationalization → JavaScript: Internationalization API

The issue has been fixed in the upstream by https://github.com/unicode-org/icu4x/pull/4536. The patch is large, so it probably cannot be cherry-pick into Firefox, so we'll need to wait until ICU4X segmenter 1.5 release.

Status: UNCONFIRMED → NEW
Ever confirmed: true

(In reply to Ting-Yu Lin [:TYLin] (PDT, UTC-7) from comment #4)

The issue has been fixed in the upstream by https://github.com/unicode-org/icu4x/pull/4536.

Good to hear that this is already fixed upstream!

The patch is large, so it probably cannot be cherry-pick into Firefox, so we'll need to wait until ICU4X segmenter 1.5 release.

Sounds reasonable to wait for the next release.

Blocks: sm-runtime
Severity: -- → S3
Priority: -- → P3

Does this also fix ങ്ക from this reddit post?

(In reply to Tom S [:evilpie] from comment #6)

Does this also fix ങ്ക from this reddit post?

Yes. I test ങ്ക via modifying this test as the following, and ങ്ക produces only two grapheme cluster breaks (begin and end).

#[test]
fn emoji_flags() {
    // https://github.com/unicode-org/icu4x/issues/4780
    let segmenter = GraphemeClusterSegmenter::new();
    let breaks: Vec<usize> = segmenter.segment_str("ങ്ക").collect();
    assert_eq!(breaks, [0, 9]);
}
Depends on: 1899411

Fixed by ICU4X 1.5

Status: NEW → RESOLVED
Closed: 2 years ago
Duplicate of bug: 1899411
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.