0
votes

I'm getting a strange error when calling the slug method of the Inflector class. Here's the code:

Inflector::slug('foo', '-');

The error I'm getting is:

Warning (2): preg_replace(): Compilation failed: nothing to repeat at offset 0 [CORE/Cake/Utility/Inflector.php, line 546]

And here's the method slug:

public static function slug($string, $replacement = '_') {
    $quotedReplacement = preg_quote($replacement, '/');

    $merge = array(
        '/[^\s\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ',
        '/\\s+/' => $replacement,
        sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '',
    );

    $map = self::$_transliteration + $merge;
    return preg_replace(array_keys($map), array_values($map), $string);
}

Any ideas what is causing the error?

Additional info: http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html

1
what cake version? works ok in 2.4.5 - cornelb
Version 2.3.0. I'll try to use the class of the version 2.4.5 to see if it works. - Brayan

1 Answers

1
votes

If anyone is coming here looking for an answer, I found my problem:

The encoding of the file wasn't set to UTF-8, and the $_transliteration items in the array at the top were not properly being encoded right.