Commit 234d024a authored by catch's avatar catch
Browse files

Issue #3181644 by alexpott, andypost, longwave, chr.fritsch: PCRE library...

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

(cherry picked from commit 7f828c96)
parent 65dc3b82
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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.
   */
+2 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
use Drupal\Component\Gettext\PoStreamReader;
use Drupal\Component\Gettext\PoMemoryWriter;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Language\LanguageInterface;

/**
 * File based string translation.
@@ -106,7 +107,7 @@ protected function getTranslationFilesPattern($langcode = NULL) {
    // 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$!';
  }

  /**
+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public function commonForm(array &$form) {
   */
  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/',
+2 −1
Original line number Diff line number Diff line
@@ -20,8 +20,9 @@ public function testInstallerTranslationFiles() {
    // 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' => [],
    ];
+4 −0
Original line number Diff line number Diff line
# This file exists to prove that
# \Drupal\Core\StringTranslation\Translator\FileTranslation::findTranslationFiles()
# does not find it. See
# \Drupal\KernelTests\Core\Installer\InstallerLanguageTest::testInstallerTranslationFiles()
Loading