Problem/Motivation

Background: https://github.com/mglaman/phpstan-drupal/issues/221

When I see the (newish) deprecated service warning in upgrade status report (on my 8.9.19 site, I get it for our favorite deprecated service, path.alias_manager), the documentation link is wrong -- specifically, it's missing the last number:

The "path.alias_manager" service is deprecated. Use "path_alias.manager" instead. See https://drupal.org/node/309208.
deprecated service warning on upgrade status report page

Correct documentation link, per core.services.yml (is that where the deprecation warning text comes from, or?): https://www.drupal.org/node/3092086

BUT, when I checked my project via drush, the documentation link is there, in full (screenshot)

$ drush upgrade_status:analyze mytheme
My Theme Name, --
Scanned on Fri, 11/05/2021 - 18:10

FILE: web/themes/mytheme/mytheme.theme

STATUS         LINE                           MESSAGE                           
--------------------------------------------------------------------------------
Check manually 95   The "path.alias_manager" service is deprecated. Use         
                    "path_alias.manager" instead. See                           
                    https://drupal.org/node/3092086                             

Steps to reproduce

Go to upgrade status report on a 8.9.19 site that has a project that uses path.alias_manager, and scan that project (in my case, it's in our site theme's .theme file). Then, click the "local scan result" that'll come up in the report.

About me:

  • mglaman/phpstan-drupal version 0.12.15
  • drupal/upgrade_status version 3.11.0
  • drupal/core version 8.9.19

Note: My only example so far is with path.alias_manager, I'm not sure if it's happening with other deprecated services, because it's the only one I've got. It would be cool if someone could try to reproduce the issue with another deprecated service, of course. Looking at core.services.yml, there are only a few other deprecated services with documentation links (and several of them point to the same documentation link as path.alias_manager).

Here are the two I found that have documentation links other than https://drupal.org/node/3092086:

  • entity.query
  • path.alias_storage

Proposed resolution

TL;DR: Probably somewhere here, though I can't figure out how -- but like, it's gotta be, right?...........
upgrade_status/src/ScanResultFormatter.php#L223

More thoughts (feelings?) --

I have no proof, but it feels like the URL is getting truncated somehow?

The link is correct when you analyze via drush, and also, I can't find any mention of "309208" without the 6 at the end, anywhere in Drupal core. (I ran grep -r "309208" web/core/ locally, and, here's a search on GitLab that's the same thing.)

So, after a lot of digging around mglaman/phpstan-drupal, the upgrade_status project, and Drupal core, my guess is that the link is getting truncated. To be clear, while this theory is my best guess, it also sounds quite unlikely 🤷‍♀️

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alisonjo315 created an issue. See original summary.

mglaman’s picture

I was able to reproduce it here: https://3v4l.org/lWPio

$api_link = 'https://api.drupal.org/api/drupal/8.9.x/search/';
$error = [
    'message' => 'The "path.alias_manager" service is deprecated. Use "path_alias.manager" instead. See https://drupal.org/node/3092086',
];
$formatted_error = preg_replace('!deprecated function ([^(]+)\(\)!', 'deprecated function <a target="_blank" href="' . $api_link . '\1">\1()</a>', $error['message']);
$formatted_error = str_replace('\\', '\\<wbr>', $formatted_error);
$formatted_error = preg_replace('!See (https://drupal.org(.\S+)).$!', 'See <a href="\1">\1<a>.', $formatted_error);
print $formatted_error;

And regex example: https://www.phpliveregex.com/p/Cwc

mglaman’s picture

Using this regex seems to fix it: See (https://drupal.org(.*)).$

The .\S+ is skipping the last character for some reason.

Gábor Hojtsy’s picture

Hm, that assumes that there is a character (not even a dot lol), after the issue link. Is this the first one where there is none? Wow.

Gábor Hojtsy’s picture

Well, the dot is swallowing the last character in the string, and here it is a significant character :D The .$! should probably be changed to (\.|$)! or somesuch to allow for either a dot or a direct string end.

mglaman’s picture

Oh snap, I see.

  path.alias_whitelist:
    alias: path_alias.whitelist
    deprecated: 'The "%service_id%" service is deprecated. Use "path_alias.whitelist" instead. See https://drupal.org/node/3092086'
  path.alias_manager:
    class: Drupal\Core\Path\AliasManager
    arguments: ['@path_alias.repository', '@path_alias.whitelist', '@language_manager', '@cache.data']
    deprecated: 'The "%service_id%" service is deprecated. Use "path_alias.manager" instead. See https://drupal.org/node/3092086'

The regex assumes punctuation. There isn't any. So the regex is broken. So it's a core bug, technically.

alison’s picture

Allowing for with/without a period at the end of the sentence makes sense to me. We could look at whether there's "supposed to be" a period at the end of those deprecation messages, in coding/grammar standards, or we could just do it as @Gábor Hojtsy suggests in #5.

I have a family thing tonight and I gotta run, but I'd love to submit a patch tomorrow if someone doesn't beat me to it -- no hard feelings if someone beats me to it, we all know "I'm definitely going to do this tomorrow" doesn't always work out.

alison’s picture

Status: Active » Needs review

Merge request submitted -- I tested on my own project, the documentation link for "path.alias_manager" is fixed.

I have not tested it with any other deprecated services (with or without documentation links).

mglaman’s picture

Tests pass! Looks good to me, but maybe we should add a test sample that proves that deprecation message is properly reported.

Kristen Pol’s picture

@mglaman Are there plans to add a test or can this be RTBCed as is?

mglaman’s picture

I think we probably need a test to verify the regex properly

Kristen Pol’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Moving back for tests per #12.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Updated a tested message and the expectation that should prove this I think. Once/if that passes, a test only patch would be useful to prove that it otherwise fails and we are good IMHO.

Gábor Hojtsy’s picture

FileSize
2.11 KB

Here is the test changes only.

Gábor Hojtsy’s picture

Hm that did not prove it...

Kristen Pol’s picture

Maybe I'm not following, but my understanding is:

1) Regex was eating the last character of the deprecation message when there wasn't a period at the end.

2) We need a test that will show the link extracted by the regex is broken before the code is fixed.

3) If this is correct, you need to test the extracted link and not the full text. i.e. the old regex should cause the link to be like:

https://www.drupal.org/project/upgrade_statu

so if you check that link is valid, you should get a 404.

Gábor Hojtsy’s picture

I think the last letter would be lost not just missing from the link. As shown in the screenshot in the issue summary too.

$formatted_error = preg_replace('!See (https://drupal.org(.\S+)).$!', 'See <a href="\1">\1<a>.', $formatted_error);

This will eat the last character, whatever it is (unescaped period at end of string matches whatever character there is). Then it will be replaced with a literal period. Because it matches to the end of the string, the character matched by the unescaped period would be lost. So I was expecting this simple test change should show it failing. It should not be lost from the link only but from the entire string.

Gábor Hojtsy’s picture

Status: Needs review » Needs work

Ok the problem with the test is that the bug is in the result formatter which is only used on the UI, so the analyzer test will not find it. We should update the UI test.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
3.39 KB

Ok now this should fail without the fix. #famouslastwords

Gábor Hojtsy’s picture

FileSize
3.18 KB

Hm, the MR branch is not up to date. Rerolled the test only.

Gábor Hojtsy’s picture

Title: Deprecated service documentation link in upgrade status report » Link formatter swallows last character if it is not a period

Meh, I give up. I think the fix is correct regardless of whether we can make the test coverage fit :D

  • 602c038 committed on 8.x-3.x
    Issue #3247970 by Gábor Hojtsy, alisonjo315, mglaman, Kristen Pol: Link...
Gábor Hojtsy’s picture

Status: Needs review » Fixed

So committed the fix as-is. Thanks all!

Kristen Pol’s picture

Ah ha! Glad you sorted it… good work everyone:)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.