[TASK] Transliterate accented characters 43/60543/4
authorDominik Merkel <merkel.dominik@googlemail.com>
Thu, 25 Apr 2019 13:03:28 +0000 (15:03 +0200)
committerRalf Zimmermann <ralf.zimmermann@tritum.de>
Thu, 25 Apr 2019 17:25:22 +0000 (19:25 +0200)
Convert accented characters in the form name
to ASCII characters

Resolves: #84533
Releases: master
Change-Id: I125a8df2f23d52d17ef2c1db4b5a9e113ae84f9c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60543
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
typo3/sysext/form/Classes/Controller/FormManagerController.php
typo3/sysext/form/Tests/Unit/Controller/FormManagerControllerTest.php

index d71505c..6a0d2d9 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Template\Components\ButtonBar;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\View\BackendTemplateView;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Localization\LanguageService;
@@ -498,7 +499,10 @@ class FormManagerController extends AbstractBackendController
      */
     protected function convertFormNameToIdentifier(string $formName): string
     {
-        $formIdentifier = preg_replace('/[^a-zA-Z0-9-_]/', '', $formName);
+        $csConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+
+        $formIdentifier = $csConverter->specCharsToASCII('utf-8', $formName);
+        $formIdentifier = preg_replace('/[^a-zA-Z0-9-_]/', '', $formIdentifier);
         $formIdentifier = lcfirst($formIdentifier);
         return $formIdentifier;
     }
index ce57de4..59fd790 100644 (file)
@@ -417,6 +417,20 @@ class FormManagerControllerTest extends UnitTestCase
     /**
      * @test
      */
+    public function convertFormNameToIdentifierConvertAccentedCharacters(): void
+    {
+        $mockController = $this->getAccessibleMock(FormManagerController::class, [
+            'dummy'
+        ], [], '', false);
+
+        $input = 'téstform';
+        $expected = 'testform';
+        $this->assertSame($expected, $mockController->_call('convertFormNameToIdentifier', $input));
+    }
+
+    /**
+     * @test
+     */
     public function convertFormNameToIdentifierRemoveSpecialChars(): void
     {
         $mockController = $this->getAccessibleMock(FormManagerController::class, [
@@ -424,7 +438,7 @@ class FormManagerControllerTest extends UnitTestCase
         ], [], '', false);
 
         $input = 'test form ä#!_-01';
-        $expected = 'testform_-01';
+        $expected = 'testformae_-01';
         $this->assertSame($expected, $mockController->_call('convertFormNameToIdentifier', $input));
     }
 }