Issue #3181644 by alexpott, andypost, longwave, chr.fritsch: PCRE library version 10.35 with pcre.jit=1 makes \Drupal\Core\StringTranslation\Translator\FileTranslation::getTranslationFilesPattern() regex misbehave
parent
6241c57f60
commit
7f828c966c
|
@ -51,6 +51,13 @@ interface LanguageInterface {
|
|||
*/
|
||||
const LANGCODE_SITE_DEFAULT = 'site_default';
|
||||
|
||||
/**
|
||||
* A regex for validating language codes according to W3C specifications.
|
||||
*
|
||||
* @see https://www.w3.org/International/articles/language-tags/
|
||||
*/
|
||||
const VALID_LANGCODE_REGEX = '[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*';
|
||||
|
||||
/**
|
||||
* The language state when referring to configurable languages.
|
||||
*/
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Drupal\Core\StringTranslation\Translator;
|
|||
use Drupal\Component\Gettext\PoStreamReader;
|
||||
use Drupal\Component\Gettext\PoMemoryWriter;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
|
||||
/**
|
||||
* File based string translation.
|
||||
|
@ -102,7 +103,7 @@ class FileTranslation extends StaticTranslation {
|
|||
// The file name matches: drupal-[release version].[language code].po
|
||||
// When provided the $langcode is use as language code. If not provided all
|
||||
// language codes will match.
|
||||
return '!drupal-[0-9a-z\.-]+\.' . (!empty($langcode) ? preg_quote($langcode, '!') : '[^\.]+') . '\.po$!';
|
||||
return '!drupal-[0-9]+\.[0-9]+\.([0-9]+|x)(-[a-z]+[0-9]*)?\.' . (!empty($langcode) ? preg_quote($langcode, '!') : LanguageInterface::VALID_LANGCODE_REGEX) . '\.po$!';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -95,7 +95,7 @@ abstract class LanguageFormBase extends EntityForm {
|
|||
*/
|
||||
public function validateCommon(array $form, FormStateInterface $form_state) {
|
||||
// Ensure sane field values for langcode and name.
|
||||
if (!isset($form['langcode_view']) && !preg_match('@^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$@', $form_state->getValue('langcode'))) {
|
||||
if (!isset($form['langcode_view']) && !preg_match('@^' . LanguageInterface::VALID_LANGCODE_REGEX . '$@', $form_state->getValue('langcode'))) {
|
||||
$form_state->setErrorByName('langcode', $this->t('%field must be a valid language tag as <a href=":url">defined by the W3C</a>.', [
|
||||
'%field' => $form['langcode']['#title'],
|
||||
':url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
|
|
|
@ -20,8 +20,9 @@ class InstallerLanguageTest extends KernelTestBase {
|
|||
// Different translation files would be found depending on which language
|
||||
// we are looking for.
|
||||
$expected_translation_files = [
|
||||
NULL => ['drupal-8.0.0-beta2.hu.po', 'drupal-8.0.0.de.po'],
|
||||
NULL => ['drupal-8.0.0-beta2.hu.po', 'drupal-8.0.0.de.po', 'drupal-8.0.x.fr-CA.po'],
|
||||
'de' => ['drupal-8.0.0.de.po'],
|
||||
'fr-CA' => ['drupal-8.0.x.fr-CA.po'],
|
||||
'hu' => ['drupal-8.0.0-beta2.hu.po'],
|
||||
'it' => [],
|
||||
];
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
# This file exists to prove that
|
||||
# \Drupal\Core\StringTranslation\Translator\FileTranslation::findTranslationFiles()
|
||||
# does not find it. See
|
||||
# \Drupal\KernelTests\Core\Installer\InstallerLanguageTest::testInstallerTranslationFiles()
|
Loading…
Reference in New Issue