function slug in inflector.php
Reported by nowashburn | April 19th, 2010 @ 10:06 PM | in 1.3.2
using cakePHP 1.3 RC4 the slug function was doing some pretty wild things such as creating wrong names for cached view files and also when using the serialize function.
I simply replaced it with the old slug function from 1.2 and hadnt had a problem since. heres the new / old function:
function slug($string, $replacement = '_', $map = array()) {
if (!class_exists('String')) {
require LIBS . 'string.php';
}
$map = array(
'/à|á|å|â/' => 'a',
'/è|é|ê|ẽ|ë/' => 'e',
'/ì|í|î/' => 'i',
'/ò|ó|ô|ø/' => 'o',
'/ù|ú|ů|û/' => 'u',
'/ç/' => 'c',
'/ñ/' => 'n',
'/ä|æ/' => 'ae',
'/ö/' => 'oe',
'/ü/' => 'ue',
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
'/ß/' => 'ss',
'/[^\w\s]/' => ' ',
'/\\s+/' => $replacement,
String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '',
);
return preg_replace(array_keys($map), array_values($map), $string);
}
the stranger thing is that the newer version did work fine on my dev machine but not production server. DEV = PHP Version 5.2.11. Production = PHP Version 5.2.5
ANOTHER EXAMPLE:
here is an example of running a string through inflector::slug. The code was placed in app_controller.php in beforeRender() just to test. here is the code:
$string = inflector::slug("HelloWorld_hi-hi-again"); echo($string);
1.3 slug function output: llo_o_ld
1.2 slug function output: HelloWorld_hi_hi_again
Comments and changes to this ticket
-

nowashburn April 14th, 2010 @ 02:15 PM
an example of a cached file name with the 1.2 function:
tcm_filmfestival_cms_gallery_categories_index_index_xml.phpand with the new 1.3 version:
lm_t_l_ll_t_o_d_d_ml.phpany other information needed please let me know.
-

nowashburn April 14th, 2010 @ 02:28 PM
attached are two xml files created with $xml->serialize. BOTH were made with 1.3 RC4 but the one named view-1.2.xml uses the old slug function as described before.
-

nowashburn April 14th, 2010 @ 02:39 PM
here is an example of running a string through inflector::slug. The code was placed in app_controller.php in beforeRender() just to test. here is the code:
$string = inflector::slug("HelloWorld_hi-hi-again"); echo($string);
1.3 slug function output:
1.2 slug function output:
llo_o_ld -

nowashburn April 14th, 2010 @ 02:39 PM
here is an example of running a string through inflector::slug. The code was placed in app_controller.php in beforeRender() just to test. here is the code:
$string = inflector::slug("HelloWorld_hi-hi-again"); echo($string);
1.3 slug function output:
1.2 slug function output:
llo_o_ld -

nowashburn April 14th, 2010 @ 02:40 PM
Dont't know why the formatting is so messed up. Please excuse the folling two comments.
here is an example of running a string through inflector::slug. The code was placed in app_controller.php in beforeRender() just to test. here is the code:
$string = inflector::slug("HelloWorld_hi-hi-again"); echo($string);
1.3 slug function output:
1.2 slug function output:
llo_o_ld -

Mark Story April 14th, 2010 @ 07:49 PM
- → Tag changed from function slug in inflector.php to defect, inflector, slug, unicode
- → Milestone set to 1.3.0
Sounds like your PCRE libraries are broken, this happens when the pcre libraries don't properly handle unicode patterns. Leaving as a defect, but I don't really know what can be done other than removing unicode support from slug() which is something I'd rather not do.
-

Gabriel Gilini April 19th, 2010 @ 03:36 PM
Just FTR, I'm having the same issue here.
Mark, do you know any way to effectively test for this PCRE defect? I've been using PCRE functions for years in my PHP build, and this is the first time I have faced this kind of issue. -

Mark Story April 19th, 2010 @ 10:06 PM
The following preg_match should show the utf-8 errors in PCRE.
$string = preg_replace('/[^\s\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu', 'posts/view/한국어/page:1/sort:asc', '_');If $string contains something that looks like
'posts_view_한국어_page_1_sort_asc'then you are ok. If you get mangled output, not ok. :) -

ADmad April 21st, 2010 @ 06:47 AM
@nowashburn @Gabriel Can you guys please post your PCRE library version so that it might help others struggling with similar problem figure out the issue.
-

Mark Story April 28th, 2010 @ 11:02 PM
- → State changed from new to hold
Moving to hold, waiting for PCRE version numbers. I can't reproduce with PCRE 7.9
-

nowashburn April 29th, 2010 @ 08:42 AM
sorry for the delay
PCRE (Perl Compatible Regular Expressions) Support enabled
PCRE Library Version 6.6 06-Feb-2006 -

bgaluszka April 30th, 2010 @ 10:00 AM
It's a problem with PCRE library. More here http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/284
"The problem was with pcre library which was compiled with --enable-utf8 and it should be with --enable-unicode-properties. This allows using extra escape sequences like \p{xx}, \P{xx}, \X. More information can be found http://www.pcre.org/pcre.txt. I'm using slackware-current to anyone who might be interested."
-

-

-

Mark Story June 25th, 2010 @ 09:42 PM
- → State changed from hold to works-for-me
Since this issue is solved by installing newer PCRE libraries I'm going to close. We want to keep the utf-8 support in inflector, and that is only possibly with utf-8 regular expressions.
-

Darren_N August 24th, 2010 @ 09:41 PM
This was definitely the PCRE problem. I had the same issues and upgraded my server to PCRE 8.02 (CentOS 5) and then upgraded PHP to 5.2.14 so it would compile in the new native PCRE settings. The view cache immediately started to use the correct filenames and cleared them on CRUD actions.
-

Moritz Reiter August 18th, 2011 @ 03:38 AM
I seem to have the same problem with Cake 1.3.11. The slug() function in the Inflector class does not work for me in the same way as described in this ticket.
I also tried the test Mark Story suggested before (http://goo.gl/S6r6t) and I get mangled output.
But phpinfo() tells me that I have PHP 5.2.14 with pcre 8.02 so that should be fine, shouldn't it?
Another possibility would be the compile flag for pcre mentioned above (--enable-utf8 vs. --enable-unicode-properties). Would there be a way to find out how my pcre lib was compiled?
-

Moritz Reiter August 24th, 2011 @ 04:09 AM
I tested the whole thing now on a MacBook with the MAMP suite and my result is: The slug() function in the Inflector class works fine but I still get the mangle output for the test Mark Story suggested.
I really don't know where to go from here.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
Repository is at http://github.com/cakephp/cakephp
Creating a bug report
When creating a bug report, please include as much relevant information as possible. Please include code to reproduce the issue. Or even better, make a unit test. Either change an existing test or add a new test to show that the expected behavior is not occuring.
People watching this ticket
Attachments
Referenced by
-
#635 Inflector::slug() issue with php 4.3.9
It's the same thing as in
http://cakephp.lighthouseapp.c...
-
#1024 Inflector::underscore corrupts UTF8 strings
Duplicate of #1008, #635, #582. The root cause is broken ...
-
#1356 Inflector::slug() bug MediaTemple servers?
Same problem as: http://cakephp.lighthouseapp.com/project...
-
#1356 Inflector::slug() bug MediaTemple servers?
Looks like you have broken PCRE libraries just like #582 ...
-
#1313 Inflector::slug does not behave as expected on CentOS
Duplicate of #582
-
#1763 PHP Warning in lib/Cake/Console/ConsoleOutput.php line 186
Just as I thought your PCRE libs are outdated. Please upd...