]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added NFC conversion where available
authorSteve Clay <steve@mrclay.org>
Tue, 26 Jun 2012 15:28:58 +0000 (11:28 -0400)
committerSteve Clay <steve@mrclay.org>
Tue, 26 Jun 2012 15:28:58 +0000 (11:28 -0400)
engine/classes/ElggTranslit.php
engine/tests/regression/trac_bugs.php

index 704c17f6ad04160da3e9f24062198780d8acc806..80930227624c4e559785b38dd1243accbc204322 100644 (file)
@@ -37,6 +37,13 @@ class ElggTranslit {
        static public function urlize($string, $separator = '-') {
                // Iñtërnâtiônàlizætiøn, AND 日本語!
 
+               // try to force combined chars because the translit map and others expect it
+               if (self::hasNormalizerSupport()) {
+                       $nfc = normalizer_normalize($string);
+                       if (is_string($nfc)) {
+                               $string = $nfc;
+                       }
+               }
                // Internationalization, AND 日本語!
                $string = self::transliterateAscii($string);
 
@@ -235,4 +242,19 @@ class ElggTranslit {
                        "\xE1\xBB\xB4" /* Ỵ */ => 'Y', "\xE1\xBB\xB5" /* ỵ */ => 'y',
                );
        }
+
+       /**
+        * Tests that "normalizer_normalize" exists and works
+        * @return bool
+        */
+       static public function hasNormalizerSupport() {
+               static $ret = null;
+               if (null === $ret) {
+                       $form_c = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
+                       $form_d = "A\xCC\x8A"; // A followed by 'COMBINING RING ABOVE' (U+030A)
+                       $ret = (function_exists('normalizer_normalize')
+                                   && $form_c === normalizer_normalize($form_d));
+               }
+               return $ret;
+       }
 }
index e81bd69363aade706d69f19325cff827fa807c38..691433a410cbb4699c13f52ba249e2b4a572fb92 100644 (file)
@@ -223,6 +223,12 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
                        "Me &amp; You" => 'me-and-you',
                );
 
+               // where available, string is converted to NFC before transliteration
+               if (ElggTranslit::hasNormalizerSupport()) {
+                       $form_d = "A\xCC\x8A"; // A followed by 'COMBINING RING ABOVE' (U+030A)
+                       $cases[$form_d] = "a";
+               }
+
                foreach ($cases as $case => $expected) {
                        $friendly_title = elgg_get_friendly_title($case);
                        $this->assertIdentical($expected, $friendly_title);