Skip to content

Commit

Permalink
Fix cyrillic characters in slugify; closes glpi-project#2964
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Feb 18, 2019
1 parent 85cf7f3 commit b6d966d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"ext-gd": "*",
"ext-zlib": "*",
"ext-curl": "*",
"ext-intl": "*",
"iamcal/lib_autolink": "~1.7",
"phpmailer/phpmailer": "~6.0",
"sabre/vobject": "~4.1",
Expand Down
3 changes: 3 additions & 0 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,9 @@ static function checkExtensions($list = null) {
'CAS' => [
'required' => false,
'class' => 'phpCAS'
],
'intl' => [
'required' => true
]
];
} else {
Expand Down
1 change: 1 addition & 0 deletions inc/toolbox.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,7 @@ public static function removeHtmlSpecialChars($string) {
* @return string
*/
public static function slugify($string) {
$string = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $string);
$string = str_replace(' ', '-', self::strtolower($string, 'UTF-8'));
$string = self::removeHtmlSpecialChars($string);
$string = preg_replace('~[^0-9a-z]+~i', '-', $string);
Expand Down
28 changes: 17 additions & 11 deletions tests/units/Toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,24 @@ public function testRemoveHtmlSpecialChars() {
$this->string($result)->isIdenticalTo($expected);
}

public function testSlugify() {
$original = 'My - string èé Ê À ß';
$expected = 'my-string-ee-e-a-sz';
$result = \Toolbox::slugify($original);

$this->string($result)->isIdenticalTo($expected);
protected function slugifyProvider() {
return [
[
'string' => 'My - string èé Ê À ß',
'expcected' => 'my-string-ee-e-a-sz'
], [
//https://github.com/glpi-project/glpi/issues/2946
'string' => 'Έρευνα ικανοποίησης - Αιτήματα',
'expcected' => 'ereuna-ikanopoieses-aitemata'
]
];
}

//https://github.com/glpi-project/glpi/issues/2946
$original = 'Έρευνα ικανοποίησης - Αιτήματα'; //el_GR
$result = \Toolbox::slugify($original);
$this->string($result)->startWith('nok_')
->length->isIdenticalTo(10 + strlen('nok_'));
/**
* @dataProvider slugifyProvider
*/
public function testSlugify($string, $expected) {
$this->string(\Toolbox::slugify($string))->isIdenticalTo($expected);
}

public function dataGetSize() {
Expand Down

0 comments on commit b6d966d

Please sign in to comment.