Problem/Motivation
\Drupal\Core\StringTranslation\Translator\FileTranslation::getTranslationFilesPattern() can produce a regex that fails on certain PHP builds.
Steps to reproduce
Set pcre.jit to 1 and run \Drupal\KernelTests\Core\Installer\InstallerLanguageTest::testInstallerTranslationFiles()
We've tried testing this on drupalci - see #2 - but it does not fail in the way it does locally. https://3v4l.org/m091V also shows that its PHP builds are not affected - interesting PHP 8 alpha 2 had a bug here...
Proposed resolution
Fix the regex returned by \Drupal\Core\StringTranslation\Translator\FileTranslation::getTranslationFilesPattern() to work regardless of compiled pcre version.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#16 | 3181644-16.patch | 4.36 KB | alexpott |
#16 | 15-16-interdiff.txt | 801 bytes | alexpott |
#15 | 3181644-15.patch | 4.35 KB | alexpott |
#15 | 8-15-interdiff.txt | 4.35 KB | alexpott |
#8 | 3181644-8.patch | 855 bytes | alexpott |
Comments
Comment #2
alexpottHere's a will-fail patch to show that the regex in \Drupal\Core\StringTranslation\Translator\FileTranslation::getTranslationFilesPattern() is broken by pcre.jit. And the other patch attached fixes this.
Comment #3
andypostWhich exact version of PHP you are using? I faced that PHP did changes in 7.4.12 by committing unreleased lib-pcre jit changes
Comment #4
chr.fritschI found this issue together with @alexpott and I ran into it with PHP 7.4.9. I didn't tested any other version.
Comment #5
andypostI bet it caused build option
--without-pcre-jit
or--with-pcre-jit
(so probably could be caught)@chr.fritsch please check which pcre version used? I'm waiting for 10.36 to try because right now (10.35 pcre) php can catch this bug with own tests https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/14061#note...
Comment #6
alexpottI'm on 7.4.10 - I guess DrupalCI is built with
-without-pcre-jit
so setting the flag is meaningless.Comment #7
alexpottWell we're not building it with
--with-pcre-jit
so I guess that's why we can't make the test fail.Comment #8
alexpottHmmm this seems to be caused by other system differences. I think DrupalCI has pcre.jit set to 1... it's the default and you have to do work to make PHP compile without it.
I think the thing to do is to fix \Drupal\Core\StringTranslation\Translator\FileTranslation::getTranslationFilesPattern() here and be done. We have test coverage in \Drupal\KernelTests\Core\Installer\InstallerLanguageTest::testInstallerTranslationFiles() so we know the regex change is not breaking anything.
Comment #9
alexpottComment #10
andypostThe 2-fail patch fails for me using
--with-external-pcre
option and following libraryComment #11
andypostI tested it manually on the setup from #10 using patch #8 and
3181644-2-will-fail.patch
before
after
Comment #12
andypostDrupal CI using
Comment #13
andypostUsed to build pcre 10.36-RC1 and it fixed the test (test pass without patch #8), so the problem caused by pcre version
Comment #14
alexpottOne question is worth asking: is changing the regex from
drupal-[0-9a-z\.-]+\.po$
todrupal-[0-9a-z\.-]+\.[^\.]+\.po$
ok?So the regex for validating langcodes is
^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$
so new regex won't work for langcodes with capital letters. See\Drupal\language\Form\LanguageFormBase::validateCommon()
and https://www.w3.org/International/articles/language-tags/We need to:
Comment #15
alexpottThis changes the regex to match version strings better (see _install_get_version_info()) and langcodes - see \Drupal\language\Form\LanguageFormBase::validateCommon()
It also doesn't have problems with PCRE 10.35.
Comment #16
alexpottLet's make the test .po file not so underlined in red in PHPStorm...
Comment #17
cilefen CreditAttribution: cilefen commentedComment #18
APolitsin CreditAttribution: APolitsin commentedI think if users can not install Drupal on default PHP installation - it's a critical problem
#3158071
Comment #19
cilefen CreditAttribution: cilefen commentedCan we close #3158071: Redirect loop during installation with non-English as a duplicate of this?
Comment #20
alexpott@cilefen I postponed that one on this just in-case there are other causes. I'm pretty certain it is a duplicate but it's hard to be 100% sure with the installer.
Comment #21
longwaveLocally the original test fails for me with PCRE 10.35:
After applying the patch the test passes. The change looks good to me so this is RTBC.
Comment #22
longwaveRetitling, as I don't think this is JIT related. I can only reproduce on PCRE 10.35. The original test passes for me on PCRE 10.32 and @andypost's earlier comments indicate that 10.34 and 10.36 are OK too.
Comment #23
longwaveConfirmed that this still needs pcre.jit=1, with JIT disabled on 10.35 the original test passes.
Comment #27
catchCommitted/pushed to 9.2.x, cherry-picked to 9.1.x and 8.9.x, thanks!
Comment #35
quietone CreditAttribution: quietone at PreviousNext commentedI have closed #3158071: Redirect loop during installation with non-English as a duplicate and am moving credit.
Comment #36
quietone CreditAttribution: quietone at PreviousNext commented