Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Security] Notify that symfony/expression-language is not installed if ExpressionLanguage is used #25823

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

Merged
merged 1 commit into from
Jan 18, 2018

Conversation

giovannialbero1992
Copy link
Contributor

@giovannialbero1992 giovannialbero1992 commented Jan 17, 2018

Q A
Branch? master for features / 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25742
License MIT
Doc PR not requested

@giovannialbero1992 giovannialbero1992 changed the title [Security] Notify that symfony/expression-language is not installe if ExpressionLanguage and ExpressionLanguagePrivider are used [Security] Notify that symfony/expression-language is not installed if ExpressionLanguage and ExpressionLanguagePrivider are used Jan 17, 2018
@@ -13,6 +13,10 @@

use Symfony\Component\ExpressionLanguage\ExpressionLanguage as BaseExpressionLanguage;

if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
throw new \LogicException('Install symfony/expression-language');
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent with (the most) similar exceptions already in the code, what about throwing a \RuntimeException with a more precise message like "The ExpressionLanguage class requires the "ExpressionLanguage" component. Install "symfony/expression-language" to use it." ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -14,6 +14,10 @@
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;

if (!interface_exists('Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface')) {
throw new \RuntimeException('The ExpressionLanguage class requires the "ExpressionLanguage" component. Install "symfony/expression-language" to use it.');
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this class is "ExpressionLanguageProvider".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I've done in a hurry, like a monkey with copy and paste.

@@ -13,6 +13,10 @@

use Symfony\Component\ExpressionLanguage\ExpressionLanguage as BaseExpressionLanguage;

if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
throw new \RuntimeException('The ExpressionLanguage class requires the "ExpressionLanguage" component. Install "symfony/expression-language" to use it.');
}
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately this approach will not work. The class must be in the "else".

Copy link
Contributor

Choose a reason for hiding this comment

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

Why ? If an exception is thrown PHP will never reach the class declaration and won't try to find the parent class.

Copy link
Member

Choose a reason for hiding this comment

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

because PHP parses class ahead of time, we already got bitten by that in the past

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes some things are done ahead of time for class declarations, but in the case we have here it works without having to put the whole class in an else clause : https://3v4l.org/mELj9

Copy link
Member

Choose a reason for hiding this comment

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

we already merged such kind of code, and it broke, opcache involved maybe
I wouldn't take the risk another time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas I've modified my commit in according with your suggestions. I hope is all ok, thank you.

@@ -14,6 +14,10 @@
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;

if (!interface_exists('Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface')) {
Copy link
Member

Choose a reason for hiding this comment

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

Done really need that logic on this class? Looks superfluous to me, but I may be missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, this class also used in ExpressionLanguage.

@giovannialbero1992 giovannialbero1992 changed the title [Security] Notify that symfony/expression-language is not installed if ExpressionLanguage and ExpressionLanguagePrivider are used [Security] Notify that symfony/expression-language is not installed if ExpressionLanguage is used Jan 17, 2018
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

last changes :)

*/
class ExpressionLanguage extends BaseExpressionLanguage
{
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
Copy link
Member

Choose a reason for hiding this comment

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

CS comment: should use BaseExpressionLanguage::class here, and

class ExpressionLanguage extends BaseExpressionLanguage
{
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
throw new \RuntimeException('The ExpressionLanguage class requires the "ExpressionLanguage" component. Install "symfony/expression-language" to use it.');
Copy link
Member

Choose a reason for hiding this comment

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

The "%s" class, with FQCN and double quotes around, with ExpressionLanguage::class given

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not the case in others similar messages (in the Serializer component for example). I guess we should harmonize them ?

Copy link
Member

Choose a reason for hiding this comment

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

Actually not: we don't harmonize such CS things because they create merge conflicts when merging lower branches into upper ones.

@giovannialbero1992 giovannialbero1992 force-pushed the 3.4 branch 2 times, most recently from 47bd5c6 to b16cdc8 Compare January 17, 2018 21:28
class ExpressionLanguage extends BaseExpressionLanguage
{
if (!class_exists(BaseExpressionLanguage::class)) {
throw new \RuntimeException(sprintf('The "%s" class requires the "ExpressionLanguage" component. Install "symfony/expression-language" to use it.', ExpressionLanguage::class));
Copy link
Member

Choose a reason for hiding this comment

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

👍 for this. To make the language consistent with other spots:

The "%s" class requires the "ExpressionLanguage" component. Try running "composer require symfony/expression-language".

Is there a specific time when this class is used? I mean, obviously, if you reference the class directly, it's used :). But is it if you try to use expressions inside, for example, access_control? I'm asking only because if there is a specific use-case that activates this class 99% of the time, it might be better to mention that use case (e.g. "To use expressions in access_control, you must install...") versus saying that that ExpressionLanguage class requires the component (when the user is not really interacting with this class directly, so might not be sure where this is coming from)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the message, for the rest i don't know if in the future someone will use this class without install ExpressionLanguage.

@xabbuh
Copy link
Member

xabbuh commented Jan 18, 2018

I wonder if we did that for other classes that extend classes coming from optional dependencies in the past. And if not, why should we do that now for this particular class only?

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(consistent with the experience provided by Flex)

class ExpressionLanguage extends BaseExpressionLanguage
{
if (!class_exists(BaseExpressionLanguage::class)) {
throw new \RuntimeException(sprintf('The "%s" class requires the "ExpressionLanguage" component. Try running "composer require symfony/expression-language".', ExpressionLanguage::class));
Copy link
Member

Choose a reason for hiding this comment

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

\LogicException !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

…f ExpressionLanguage and ExpressionLanguagePrivider are used
@fabpot
Copy link
Member

fabpot commented Jan 18, 2018

Thank you @giovannialbero1992.

@fabpot fabpot merged commit 6aa2b7c into symfony:3.4 Jan 18, 2018
fabpot added a commit that referenced this pull request Jan 18, 2018
…installed if ExpressionLanguage is used (giovannialbero1992)

This PR was merged into the 3.4 branch.

Discussion
----------

[Security] Notify that symfony/expression-language is not installed if ExpressionLanguage is used

| Q             | A
| ------------- | ---
| Branch?       | master for features / 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25742
| License       | MIT
| Doc PR        | not requested

Commits
-------

6aa2b7c [Security] Notify that symfony/expression-language is not installed if ExpressionLanguage and ExpressionLanguagePrivider are used
@fabpot fabpot mentioned this pull request Jan 29, 2018
@fabpot fabpot mentioned this pull request Jan 29, 2018
greg0ire added a commit to greg0ire/core that referenced this pull request Mar 28, 2018
This is broken since sf 3.4.4, see symfony/symfony#25823
One of api platforms listener depends on a file that now throws if it is
loaded and the expression language component is missing. The solution is
to avoid creating the service if the component is missing.
This fixes an error people will have even if they do not use the
access_control annotation attribute.
greg0ire added a commit to greg0ire/core that referenced this pull request Mar 28, 2018
This is broken since sf 3.4.4, see symfony/symfony#25823
One of api platforms listener depends on a file that now throws if it is
loaded and the expression language component is missing. The solution is
to avoid creating the service if the component is missing.
This fixes an error people will have even if they do not use the
access_control annotation attribute.
meyerbaptiste pushed a commit to greg0ire/core that referenced this pull request Mar 28, 2018
This is broken since sf 3.4.4, see symfony/symfony#25823
One of api platforms listener depends on a file that now throws if it is
loaded and the expression language component is missing. The solution is
to avoid creating the service if the component is missing.
This fixes an error people will have even if they do not use the
access_control annotation attribute.
soyuka pushed a commit to soyuka/core that referenced this pull request Mar 30, 2018
This is broken since sf 3.4.4, see symfony/symfony#25823
One of api platforms listener depends on a file that now throws if it is
loaded and the expression language component is missing. The solution is
to avoid creating the service if the component is missing.
This fixes an error people will have even if they do not use the
access_control annotation attribute.
soyuka pushed a commit to soyuka/core that referenced this pull request Apr 3, 2018
This is broken since sf 3.4.4, see symfony/symfony#25823
One of api platforms listener depends on a file that now throws if it is
loaded and the expression language component is missing. The solution is
to avoid creating the service if the component is missing.
This fixes an error people will have even if they do not use the
access_control annotation attribute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.