Problem/Motivation
Originally discovered at #3093789-3: system_requirements() strips core compatibility in really fragile and dangerous way when comparing versions
core/modules/system/src/Form/ModulesListForm.php has a buildRow() method. It's currently doing this:
if (!$dependency_object->isCompatible(str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']))) {
...
}
This is problematic for a few reasons:
- str_replace() isn't careful about where in the version string it's stripping
8.x- from.
\Drupal\Core\Extension\Dependency::isCompatible() already gracefully handles version strings with a core compatibility part. Stripping anything (even if we were more careful and using preg_replace() or something) risks comparing against unintended versions.
- If you happen to be on version
8.x-8.x-dev of a given module, you end up with a version string of just dev which completely breaks all the intended logic.
Proposed resolution
Stop stripping the \Drupal::CORE_COMPATIBILITY part of version strings before using \Drupal\Core\Extension\Dependency::isCompatible().
Remaining tasks
Do it.
- Make sure the test coverage is good.
- Review.
- RTBC.
- Commit.
User interface changes
-
API changes
-
Data model changes
-
Release notes snippet
-
Comments
Comment #3
dwwI haven't looked into the test coverage yet, but here's a patch to get us started.
Also, crediting @tedbow who ran grep in the other issue to find this bug. ;)
Comment #5
dwwUgh, I was wrong at #3093789-4. See #3093789-9: system_requirements() strips core compatibility in really fragile and dangerous way when comparing versions for more.
This will pass. Still needs improved test coverage.
The whole patch is different, interdiff would be meaningless.
Comment #6
dwwComment #12
joachim commentedIs this stray debug code?
Perhaps out of scope and better be done in a follow-up, but I think this fairly messy mucking about with version numbers would be nicer if it were wrapped up in a helper, maybe a static method on Drupal\Core\Extension\Extension?
Comment #14
dcam commentedThis code got moved around, but ultimately #3086845: Module constraint checks fail incorrectly due to str_replace applied the exact same proposed fix to it. This issue is outdated.