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

Str::headline does not work with umlauts #40468

Closed
cemrich opened this issue Jan 18, 2022 · 3 comments
Closed

Str::headline does not work with umlauts #40468

cemrich opened this issue Jan 18, 2022 · 3 comments

Comments

@cemrich
Copy link

cemrich commented Jan 18, 2022

  • Laravel Version: 8.78.1
  • PHP Version: 8.1.1
  • Database Driver & Version:

Description:

Illuminate\Support\Str::headline does not support umlauts (like ö,ä,ü). There are two related bugs I can see:

  1. Uppercase umlauts are not detected as uppercase.
  2. Umlauts at the beginning of a word do not get capitalized.

Steps To Reproduce:

Umlauts at the beginning of a word do not get capitalized

public function test_make_umlauts_uppercase() {
    $input = 'ärmere-öffentliche-überraschungen-sind-öde';
    $expected = 'Ärmere Öffentliche Überraschungen Sind Öde';
    $output = Str::headline($input);
    $this->assertEquals($expected, $output);
}

Yields the output:

Failed asserting that two strings are equal.
Expected :'Ärmere Öffentliche Überraschungen Sind Öde'
Actual   :'ärmereöffentlicheüberraschungen Sindöde'

Uppercase umlauts are not detected as uppercase

public function test_detect_uppercase_umlauts() {
    $input = 'sindÖdeUndSo';
    $expected = 'Sind Öde Und So';
    $output = Str::headline($input);
    $this->assertEquals($expected, $output);
}

Yields the output:

Failed asserting that two strings are equal.
Expected :'Sind Öde Und So'
Actual   :'SindÖde Und So'
@foremtehan
Copy link
Contributor

@stevebauman

@driesvints
Copy link
Member

We'd welcome PR's for this, thank you.

@stevebauman
Copy link
Contributor

This is because ucwords() doesn't handle unicode characters:

// ärmere öffentliche
echo ucwords('ärmere öffentliche');

This means Str::studly() or anything relying on that method also does not work with unicode characters.

We'll have to be crafty and use mb_convert_case(). I'll see if I can come up with something 👍

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

4 participants