Extracting update text with update_get_update_list() should handle all line endings

Created on 30 April 2021, over 3 years ago
Updated 21 March 2023, over 1 year ago

Problem/Motivation

We are developing on windows and due to the default setting of git's core.autocrlf = true setting all line endings are handled by git.
This comes from GitLab's overall suggestion to setting up like this.
composer will checkout with git's cli if you are using dev-master version constraint.

So if you are using drush to make the database updates on windows with cygwin the table output is printed a little bit slipped.
First I thought it is related to drush, but moshe showed me the right code base where it happens. Thanks for this!

https://github.com/drupal/drupal/blob/9.2.x/core/includes/update.inc#L40...

// The description for an update comes from its Doxygen.
$func = new ReflectionFunction($module . '_update_' . $update);
$patterns = [
  '/^\s*[\/*]*/',
  '/(\n\s*\**)(.*)/',
  '/\/$/',
  '/^\s*/',
];
$replacements = ['', '$2', '', ''];
$description = preg_replace($patterns, $replacements, $func->getDocComment());
$ret[$module]['pending'][$update] = "$update - $description";

I think we could easily fix that by normalizing the line endings before extracting the description text.

// The description for an update comes from its Doxygen.
$func = new ReflectionFunction($module . '_update_' . $update);
$patterns = [
  '/^\s*[\/*]*/',
  '/(\n\s*\**)(.*)/',
  '/\/$/',
  '/^\s*/',
];
$replacements = ['', '$2', '', ''];
$description = preg_replace('/\r\n|\r/', "\n", $func->getDocComment());
$description = preg_replace($patterns, $replacements, $description);
$ret[$module]['pending'][$update] = "$update - $description";

What do you think?

Steps to reproduce

Requirement: The doc comment of the hook_update_N or other update type has to have crlf line endings

  1. drush updb -y

Proposed resolution

Normalize line endings via another preg_replace() in update_get_update_list()
Found that solution on TestDiscovery in Core: https://github.com/drupal/drupal/blob/9.2.x/core/lib/Drupal/Core/Test/Te...

Remaining tasks

  • Review
  • Commit

User interface changes

Improved CLI table output via drush

I can elaborate on this with a merge request if you want.

🐛 Bug report
Status

Needs work

Version

10.1

Component
Database update 

Last updated 10 days ago

No maintainer
Created by

🇩🇪Germany sunlix Wesel

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024