-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Autoload relative paths first to avoid confusion with files from the global include path #2751
Conversation
…th files from the global include path
Workaround we deployed for Coder: pfrenssen/coder#72 . We are just using a more unique autoload file name in the hopes that it does not get confused with other PHP files on the user's system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested this yet, but this change looks sane to me.
// Try relative autoload paths first. | ||
$relativePath = Util\Common::realPath(dirname($rulesetPath).DIRECTORY_SEPARATOR.$autoloadPath); | ||
|
||
if ($relativePath !== false && is_file($$relativePath) === true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double $
needs to be removed here. I'll do this while merging.
Thanks a lot for this fix. |
Ah, very sorry for the double $. That's what I get for making last minute changes. Let me know If there is a good way to write a test for this. |
Not a problem at all :)
I don't have one right now. |
Problem: autoload files are confused with globally available files. See pfrenssen/coder#54
If you specify
<autoload>./autoload.php</autoload>
in your ruleset.xml file then a completely different autoload.php file from your system might be executed, even although you specified a relative path.Steps to reproduce:
composer install
./vendor/bin/phpcs --standard=./standard test.php
Output:
PHP Parse error: syntax error, unexpected 'invalid' (T_STRING) in test_phpcs/autoload.php on line 3
Which means the wrong autoload.php file was included.
Proposed solution: Try to include relative paths first, then try global paths.
Not sure how we can test this, any tips for that?