AliasManager->getAliasByPath() handles $path in confusing manner.

Created on 29 June 2015, about 9 years ago
Updated 12 April 2024, 5 months ago

Problem/Motivation

AliasManager->getAliasByPath() handles $path in array fashion. While this works, it obfuscates the code - $path is required by the API to be a string.

if ($path[0] !== '/') {

The merge request handles the path with str_starts_with() instead which both ensures it is a string and checks that it begins with a slash.

Steps to reproduce

See code in AliasManager->getAliasByPath()

Proposed resolution

Use str_starts_with()

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None

🐛 Bug report
Status

Fixed

Version

10.3

Component
Path 

Last updated 12 days ago

  • Maintained by
  • 🇬🇧United Kingdom @catch
Created by

🇫🇮Finland lauriii Finland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • First commit to issue fork.
  • Merge request !7181Update path validation for clarity → (Open) created by pameeela
  • Pipeline finished with Success
    6 months ago
    Total: 578s
    #129231
  • 🇦🇺Australia pameeela

    This is still valid, but I think there's a better way to do it now. Created an MR using if (!str_starts_with($path, '/')). I didn't include the assert because I don't understand why it's necessary but easy to add if others think it is.

    Noting also there are three other instances of if ($path[0] !== '/') in the code, not sure if we want to change all of them here or not.

  • Status changed to Needs review 6 months ago
  • 🇳🇱Netherlands Lendude Amsterdam

    I see plenty of coverage for this method in \Drupal\Tests\path_alias\Unit\AliasManagerTest but none that tests the exception being thrown (as far as I can tell), so probably good to add a small test method there that tests this

  • 🇦🇺Australia pameeela

    @catch also said in Slack that we should update all of the instances of this. But given that it's somewhat widely used I'm thinking this is really a task to move away from the array syntax?

    There are also actually seven instances rather than four, some were slightly different so didn't find them initially.

  • 🇦🇺Australia pameeela

    Added the test (thanks @larowlan ;) ) and I think now that we're into tests territory the other instances should be handled separately. As that's a lot of changes to cram into this issue.

  • Pipeline finished with Failed
    5 months ago
    Total: 165s
    #130271
  • Pipeline finished with Success
    5 months ago
    Total: 529s
    #130292
  • Status changed to Needs work 5 months ago
  • 🇺🇸United States smustgrave

    Can the issue summary be updated to use the issue summary template please.

  • Status changed to RTBC 5 months ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Updated the IS, code looks good.

    • catch committed ab22c1f3 on 10.3.x
      Issue #2514196 by pameeela, Aki Tendo, Lendude, lauriii: AliasManager->...
    • catch committed 29fcd958 on 11.x
      Issue #2514196 by pameeela, Aki Tendo, Lendude, lauriii: AliasManager->...
  • Status changed to Fixed 5 months ago
  • 🇬🇧United Kingdom catch

    Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

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

Production build 0.71.5 2024