Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadServices: tighten up file match regex #16377

Merged
merged 1 commit into from
Jan 26, 2020

Conversation

ejegg
Copy link
Contributor

@ejegg ejegg commented Jan 24, 2020

Overview

Tighten up a regular expression used to find files so that it doesn't match a partial path.

Before

Civi code living under a path containing the characters 'php'
(such as ~/src/php/civicrm) will crash trying to load services with
a message like the following:
ReflectionException: Class Civi\Api4\Service\Spec\Provider\src
does not exist in ReflectionClass->__construct()

After

Civi loads services normally no matter what the enclosing path

Technical Details

The regex needs a $ anchor at the end because it's looking for files ending in php. It also needed the '.' escaped so it only matches a literal '.' and not any character.

Comments

There's another PR against master: #16376

Before: Civi code living under a path containing the characters php
(such as ~/src/php/civicrm) will crash trying to load services with
a message like the following:
   ReflectionException: Class Civi\Api4\Service\Spec\Provider\src
   does not exist in ReflectionClass->__construct()

After: Civi loads services normally no matter what the enclosing path
@civibot
Copy link

civibot bot commented Jan 24, 2020

(Standard links)

@civibot civibot bot added the 5.22 label Jan 24, 2020
@@ -86,7 +86,7 @@ public static function loadServices($namespace, $tag, $container) {
$container->addResource($resource);
foreach (glob("$path*.php") as $file) {
$matches = [];
preg_match('/(\w*).php/', $file, $matches);
preg_match('/(\w*)\.php$/', $file, $matches);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this scenario, but this does look like a more correct implementation of "find things ending in *.php" 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totten i'm guessing also if there was a problem with this right then the api_v4_unit tests would fail right because this merges in the core resources + extension resources

@seamuslee001
Copy link
Contributor

Given Tim's supportive comment, i tested this out by applying the regex locally and installed the deduper and afform extensions and confirmed that this still worked as expected.

@seamuslee001 seamuslee001 merged commit 26d5758 into civicrm:5.22 Jan 26, 2020
@ejegg ejegg deleted the serviceFileFinder-5.22 branch January 28, 2020 18:30
ejegg added a commit to ejegg/civicrm-core that referenced this pull request Feb 21, 2020
Before: Civi code living under a path containing the characters php
(such as ~/src/php/civicrm) will fail to load the API4 explorer with
a message like the following:
    ReflectionException: "Class \Civi\Api4\src does not exist"

After: API4 explorer loads no matter what the enclosing path

Very similar to PR civicrm#16377
ejegg added a commit to ejegg/civicrm-core that referenced this pull request Feb 21, 2020
Before: Civi code living under a path containing the characters php
(such as ~/src/php/civicrm) will fail to load the API4 explorer with
a message like the following:
    ReflectionException: "Class \Civi\Api4\src does not exist"

After: API4 explorer loads no matter what the enclosing path

Very similar to PR civicrm#16377
magnolia61 pushed a commit to magnolia61/civicrm-core that referenced this pull request Mar 3, 2020
Before: Civi code living under a path containing the characters php
(such as ~/src/php/civicrm) will fail to load the API4 explorer with
a message like the following:
    ReflectionException: "Class \Civi\Api4\src does not exist"

After: API4 explorer loads no matter what the enclosing path

Very similar to PR civicrm#16377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants