Skip to content

normalize_utf32: keep grapheme-break sentinels when stripping control characters - #371

Merged
stevengj merged 4 commits into
JuliaStrings:masterfrom
fhgffy:fix/stripcc-charbound
Oct 12, 2026
Merged

stevengj merged 4 commits into
JuliaStrings:masterfrom
fhgffy:fix/stripcc-charbound

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

UTF8PROC_CHARBOUND and UTF8PROC_STRIPCC don't work together: the STRIPCC pass in utf8proc_normalize_utf32() treats every value below 0x20 as a control character, and that includes the negative sentinels CHARBOUND puts before each grapheme. All the boundary markers get dropped:

utf8proc_map("ab\ncd", ..., UTF8PROC_CHARBOUND)                    -> "\xffa\xffb\xff\n\xffc\xffd"
utf8proc_map("ab\ncd", ..., UTF8PROC_CHARBOUND | UTF8PROC_STRIPCC) -> "ab cd"   (no markers at all)

This is the same kind of problem #355 fixed in the compose loop.

The fix only strips non-negative codepoints. When a control character is removed, it also drops the sentinel right before it, so the output doesn't get an empty grapheme (two 0xff bytes in a row). That works because a control character is always a grapheme of its own; CR LF is handled earlier as an NLF sequence. With the patch the second call gives "\xffa\xffb\xff \xffc\xffd".

Added a regression test to test/graphemetest.c next to the issue 356 one. It fails on master ("returned length 4, expected 8") and passes with the change. make check passes.

… characters

With UTF8PROC_STRIPCC, everything below 0x20 was treated as a control
character, including the negative sentinels that UTF8PROC_CHARBOUND
inserts before each grapheme. So CHARBOUND|STRIPCC returned the text
without any 0xff boundary markers.

Only strip non-negative codepoints, and when a control character is
removed, drop the sentinel in front of it as well so that it doesn't
leave an empty grapheme behind.
Comment thread utf8proc.c Outdated
Comment thread test/graphemetest.c
Comment thread utf8proc.c Outdated
Comment thread test/graphemetest.c Outdated
Comment thread test/graphemetest.c
@stevengj
stevengj merged commit 3522df6 into JuliaStrings:master Oct 12, 2026
14 checks passed
@stevengj

Copy link
Copy Markdown
Member

Thanks!

DomingoGP added a commit to DomingoGP/utf8proc_pascal that referenced this pull request Oct 17, 2026
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

Successfully merging this pull request may close these issues.

3 participants