Issue #2508654 by chx, dawehner, Chi: File inclusion in transliteration service
parent
13419847da
commit
337f182057
|
@ -243,7 +243,7 @@ class PhpTransliteration implements TransliterationInterface {
|
||||||
protected function readLanguageOverrides($langcode) {
|
protected function readLanguageOverrides($langcode) {
|
||||||
// Figure out the file name to use by sanitizing the language code,
|
// Figure out the file name to use by sanitizing the language code,
|
||||||
// just in case.
|
// just in case.
|
||||||
$file = $this->dataDirectory . '/' . preg_replace('[^a-zA-Z\-]', '', $langcode) . '.php';
|
$file = $this->dataDirectory . '/' . preg_replace('/[^a-zA-Z\-]/', '', $langcode) . '.php';
|
||||||
|
|
||||||
// Read in this file, which should set up a variable called $overrides,
|
// Read in this file, which should set up a variable called $overrides,
|
||||||
// which will be local to this function.
|
// which will be local to this function.
|
||||||
|
|
|
@ -37,7 +37,7 @@ interface TransliterationInterface {
|
||||||
* The string to transliterate.
|
* The string to transliterate.
|
||||||
* @param string $langcode
|
* @param string $langcode
|
||||||
* (optional) The language code of the language the string is in. Defaults
|
* (optional) The language code of the language the string is in. Defaults
|
||||||
* to 'en' if not provided.
|
* to 'en' if not provided. Warning: this can be unfiltered user input.
|
||||||
* @param string $unknown_character
|
* @param string $unknown_character
|
||||||
* (optional) The character to substitute for characters in $string without
|
* (optional) The character to substitute for characters in $string without
|
||||||
* transliterated equivalents. Defaults to '?'.
|
* transliterated equivalents. Defaults to '?'.
|
||||||
|
|
|
@ -10,13 +10,14 @@ namespace Drupal\Tests\Component\Transliteration;
|
||||||
use Drupal\Component\Transliteration\PhpTransliteration;
|
use Drupal\Component\Transliteration\PhpTransliteration;
|
||||||
use Drupal\Component\Utility\Random;
|
use Drupal\Component\Utility\Random;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
use org\bovigo\vfs\vfsStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Transliteration component functionality.
|
* Tests Transliteration component functionality.
|
||||||
*
|
*
|
||||||
* @group Transliteration
|
* @group Transliteration
|
||||||
*
|
*
|
||||||
* @coversClass \Drupal\Component\Transliteration\PhpTransliteration
|
* @coversDefaultClass \Drupal\Component\Transliteration\PhpTransliteration
|
||||||
*/
|
*/
|
||||||
class PhpTransliterationTest extends UnitTestCase {
|
class PhpTransliterationTest extends UnitTestCase {
|
||||||
|
|
||||||
|
@ -168,4 +169,24 @@ class PhpTransliterationTest extends UnitTestCase {
|
||||||
$this->assertSame($trunc_output, $transliteration->transliterate($input, 'de', '?', 18), 'Truncating to 18 characters works');
|
$this->assertSame($trunc_output, $transliteration->transliterate($input, 'de', '?', 18), 'Truncating to 18 characters works');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests inclusion is safe.
|
||||||
|
*
|
||||||
|
* @covers ::readLanguageOverrides
|
||||||
|
*/
|
||||||
|
public function testSafeInclude() {
|
||||||
|
// The overrides in the transliteration data directory transliterates 0x82
|
||||||
|
// into "safe" but the overrides one directory higher transliterates the
|
||||||
|
// same character into "security hole". So by using "../index" as the
|
||||||
|
// language code we can test the ../ is stripped from the langcode.
|
||||||
|
vfsStream::setup('transliteration', NULL, [
|
||||||
|
'index.php' => '<?php $overrides = ["../index" => [0x82 => "security hole"]];',
|
||||||
|
'dir' => [
|
||||||
|
'index.php' => '<?php $overrides = ["../index" => [0x82 => "safe"]];',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$transliteration = new PhpTransliteration(vfsStream::url('transliteration/dir'));
|
||||||
|
$transliterated = $transliteration->transliterate(chr(0xC2) . chr(0x82), '../index');
|
||||||
|
$this->assertSame($transliterated, 'safe');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue