public function PhpTransliterationTest::testSafeInclude in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Component\Transliteration\PhpTransliterationTest::testSafeInclude()
Tests inclusion is safe.
@covers ::readLanguageOverrides
File
- core/
tests/ Drupal/ Tests/ Component/ Transliteration/ PhpTransliterationTest.php, line 226
Class
- PhpTransliterationTest
- Tests Transliteration component functionality.
Namespace
Drupal\Tests\Component\TransliterationCode
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('safe', $transliterated);
}