Str::slug() drops combining marks, misspelling Thai, Hindi and decomposed accents
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start at the Str::slug() and Str::title() implementations; the issue identifies character handling as the source and suggests walking extended grapheme clusters. Check the existing string tests for slug and title behavior, then add coverage for combining marks in Thai, Hindi, and decomposed accents. Done when those marks are preserved and the decomposed title is not split into a new word; pull request #830 is already open.
Written by the indexing model from the issue text.
Description
Str::slug() keeps letters and digits by checking each char with is_alphanumeric(). A combining mark (Unicode category M) is not alphanumeric on its own, so it is dropped even when it belongs to the letter before it. Text in Thai, Hindi and other scripts that write vowels or tones as marks comes out misspelled, and an accent stored in decomposed form (NFD, common in text that came through macOS) disappears.
use laravel::str::Str;
"ร้านทอง ออนไลน์".slug(); // "รานทอง-ออนไลน" expected "ร้านทอง-ออนไลน์"
"น้ำแข็ง".slug(); // "นำแขง" expected "น้ำแข็ง"
"नमस्ते दुनिया".slug(); // "नमसते-दुनिया" expected "नमस्ते-दुनिया"
"Cafe\u{301} vu".slug(); // "cafe-vu" expected "cafe\u{301}-vu"
"Café vu".slug(); // "café-vu" (the same word, precomposed)
The Thai results are different words: the tone mark ้ (U+0E49), the ็ (U+0E47) and the ์ (U+0E4C) are gone. The same word also gets two different slugs depending on whether é is one code point or e plus U+0301, while the docs say the slug "keeps letters and digits as they are, accents included".
Str::title() has the same cause: after a decomposed accent it starts a new word, so "re\u{301}sume\u{301}".title() gives "Re\u{301}Sume\u{301}".
For reference, PHP Laravel's Str::slug($value, '-', null) gives the same รานทอง because its [^\pL\pN\s] class has no \pM; with the default language: 'en' it returns an empty string for Thai. So this looks inherited rather than intended.
A fix is to walk extended grapheme clusters instead of chars and keep or drop the whole cluster based on its first character. I'll open a PR with that.
- Dominant language
- Rust
- Stars
- 847
- Forks
- 174
- Avg merge
- 5h 40m
- Merged PRs (30d)
- 167
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from laravel/rust-framework
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
laravel/rust-framework#864 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
laravel/rust-framework#876 ·
Maintainers usually reply within 1 day
-
Case-sensitive contains, starts_with and ends_with that match % and _ literally on every databaseOpen
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#874 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
laravel/rust-framework#873 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#872 ·
Maintainers usually reply within 1 day
All issues in laravel/rust-framework
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neuralmagic/crucible#579 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
eclipse-score/kyron#249 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
seanmonstar/reqwest#3157 ·
Maintainers usually reply within 2 days