]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #4972: More robust friendly titles implementation
authorSteve Clay <steve@mrclay.org>
Mon, 1 Apr 2013 01:09:07 +0000 (21:09 -0400)
committerSteve Clay <steve@mrclay.org>
Mon, 1 Apr 2013 01:09:07 +0000 (21:09 -0400)
engine/classes/ElggTranslit.php
engine/lib/output.php
engine/tests/regression/trac_bugs.php

index 601965c11ad9e427667a7d0d8c6abf6e5e8e97c8..4ae1d247954ec9a47e80d0bb4e1217160fe3a54e 100644 (file)
@@ -49,10 +49,19 @@ class ElggTranslit {
                // Internationalization, AND 日本語!
                $string = self::transliterateAscii($string);
 
-               // more translation
+               // allow HTML tags in titles
+               $string = preg_replace('~<([a-zA-Z][^>]*)>~', ' $1 ', $string);
+
+               // more substitutions
+               // @todo put these somewhere else
                $string = strtr($string, array(
-                       // Euro/GBP
-                       "\xE2\x82\xAC" /* € */ => 'E', "\xC2\xA3" /* £ */ => 'GBP',
+                       // currency
+                       "\xE2\x82\xAC" /* € */ => ' E ',
+                       "\xC2\xA3" /* £ */ => ' GBP ',
+                       
+                       "&" => ' and ',
+                       ">" => ' greater than ',
+                       "<" => ' less than ',
                ));
 
                // remove all ASCII except 0-9a-zA-Z, hyphen, underscore, and whitespace
index da8e1ab862c7e17f23135530bdd3cb6137655575..c5a04989b3975f4eb81aee7081d03cb4d6b633f3 100644 (file)
@@ -284,11 +284,9 @@ function elgg_get_friendly_title($title) {
                return $result;
        }
 
-       // handle some special cases
-       $title = str_replace('&amp;', 'and', $title);
-       // quotes and angle brackets stored in the database as html encoded
-       $title = htmlspecialchars_decode($title);
-
+       // titles are often stored HTML encoded
+       $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
+       
        $title = ElggTranslit::urlize($title);
 
        return $title;
index 691433a410cbb4699c13f52ba249e2b4a572fb92..58444dd399f15d7537fda3c941f1975b0b7ff0f8 100644 (file)
@@ -206,21 +206,23 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
         */
        public function test_friendly_title() {
                $cases = array(
+                       // acid test
+                       "B&N > Amazon, OK? <bold> 'hey!' $34"
+                       => "b-and-n-greater-than-amazon-ok-bold-hey-34",
+
                        // hyphen, underscore and ASCII whitespace replaced by separator,
                        // other non-alphanumeric ASCII removed
-                       "a-a_a a\na\ra\ta\va!a\"a#a\$a%a&a'a(a)a*a+a,a.a/a:a;a<a=a>a?a@a[a\\a]a^a`a{a|a}a~a"
-                       => "a-a-a-a-a-a-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
-
+                       "a-a_a a\na\ra\ta\va!a\"a#a\$a%a&a'a(a)a*a+a,a.a/a:a;a=a?a@a[a\\a]a^a`a{a|a}a~a"
+                       => "a-a-a-a-a-a-aaaaaaa-and-aaaaaaaaaaaaaaaaaaaaaaa",
+                       
                        // separators trimmed
-                       "-_ hello _-" => "hello",
+                       "-_ hello _-" 
+                       => "hello",
 
                        // accents removed, lower case, other multibyte chars are URL encoded
                        "I\xC3\xB1t\xC3\xABrn\xC3\xA2ti\xC3\xB4n\xC3\xA0liz\xC3\xA6ti\xC3\xB8n, AND \xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E"
                                // Iñtërnâtiônàlizætiøn, AND 日本語
                        => 'internationalizaetion-and-%E6%97%A5%E6%9C%AC%E8%AA%9E',
-
-                       // some HTML entity replacements
-                       "Me &amp; You" => 'me-and-you',
                );
 
                // where available, string is converted to NFC before transliteration