Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Routing] fix conflict with param named class in attribute#40244

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@nlhommet
Copy link
Contributor

@nlhommetnlhommet commentedFeb 18, 2021
edited by nicolas-grekas
Loading

QA
Branch4.4
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#40225
LicenseMIT
Doc PR-

Fix conflict with AnnotationFileLoader and class PHP8 Attribute with param named "class"

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbotcarsonbot changed the title[Routing] fix conflict with param named class in attriburefix conflict with param named class in attribureFeb 18, 2021
@nicolas-grekasnicolas-grekas changed the titlefix conflict with param named class in attribure[Routing] fix conflict with param named class in attribureFeb 18, 2021
@nicolas-grekasnicolas-grekas added this to the5.2 milestoneFeb 18, 2021
@nicolas-grekasnicolas-grekas changed the base branch from5.x to5.2February 18, 2021 16:51
@nicolas-grekas
Copy link
Member

Can you please rebase+retarget on 5.2 if that's really the target?

@nicolas-grekasnicolas-grekas changed the base branch from5.2 to5.xFebruary 18, 2021 16:52
@nlhommetnlhommet changed the base branch from5.x to5.2February 18, 2021 17:21
@nlhommetnlhommetforce-pushed theissue-40225/annotation-file-loader branch from9d6129b to0c77083CompareFebruary 18, 2021 17:29
@nlhommet
Copy link
ContributorAuthor

Sorry it's my first PR, can you tell me how to correct my PR to be on 5.2?

@wouterjwouterj removed their request for reviewFebruary 18, 2021 21:18
@nicolas-grekasnicolas-grekas changed the base branch from5.2 to5.xFebruary 18, 2021 23:16
@nicolas-grekasnicolas-grekas changed the base branch from5.x to5.2February 18, 2021 23:18
@nicolas-grekasnicolas-grekasforce-pushed theissue-40225/annotation-file-loader branch from0c77083 to197843dCompareFebruary 18, 2021 23:18
@nicolas-grekas
Copy link
Member

I force-pushed on your fork.
FYI, I usedgit rebase -i to do the rebase on 5.2.
Do you think you could add a test case, please?
(don't miss fetching your remote branch first of course)

@derrabus
Copy link
Member

Are we sure that 4.4 is not affected?

@nicolas-grekasnicolas-grekas changed the base branch from5.2 to4.4February 19, 2021 07:30
@nicolas-grekasnicolas-grekasforce-pushed theissue-40225/annotation-file-loader branch from197843d toa6b2aaaCompareFebruary 19, 2021 07:30
@nicolas-grekasnicolas-grekas modified the milestones:5.2,4.4Feb 19, 2021
@nicolas-grekas
Copy link
Member

(now targetting 4.4)

@nlhommet
Copy link
ContributorAuthor

Tx for the help.
This impacts all branches compatible with PHP8 Attributes.
I set up tests today.

nicolas-grekas and derrabus reacted with thumbs up emoji

@nlhommet
Copy link
ContributorAuthor

I need to understand why it does not work in PHP7.1 on multiline Attributes

@nlhommet
Copy link
ContributorAuthor

I think there are tests that can only be done in PHP8.
Because an Attributes multiline like this

#[FooAttributes(    class: User::class,    foo: [        'bar' => ['foo','bar'],        'foo'    ])]

is not recognized as a valid instruction in PHP7.X.

With#[FooAttributes(class: User::class,foo: ['bar' => ['foo','bar'],'foo'])], the Attribute is recognized as comment in PHP7.X and therefore poses no problem.

@nicolas-grekas
Copy link
Member

I think there are tests that can only be done in PHP8.

correct. You can add the@requires PHP 8 annotation on top of those tests.

@nicolas-grekasnicolas-grekas changed the title[Routing] fix conflict with param named class in attribure[Routing] fix conflict with param named class in attributeFeb 19, 2021
@derrabus
Copy link
Member

Thank you for working on this. However, I'm not convinced that bracket counting is the way we should fix this. We already have a piece of code in that file that handles incorrectT_CLASS tokens and I think we can extend that logic.

diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php--- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php(revision eeed8c8e847b81ea5d16685395e85a1df9077449)+++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php(date 1613917175487)@@ -100,20 +100,8 @@             $nsTokens[T_NAME_QUALIFIED] = true;         }-        $openBrackets = 0;         for ($i = 0; isset($tokens[$i]); ++$i) {             $token = $tokens[$i];-            if (80000 <= \PHP_VERSION_ID) {-                if (\T_ATTRIBUTE === ($token[0] ?? 0) || ($openBrackets > 0 && '[' === $token)) {-                    ++$openBrackets;-                }-                if ($openBrackets > 0 && ']' === $token) {-                    --$openBrackets;-                }-                if ($openBrackets > 0) {-                    continue;-                }-            }              if (!isset($token[1])) {                 continue;@@ -146,6 +134,15 @@                         break;                     }                 }+                for ($j = $i + 1; isset($tokens[$j]); ++$j) {+                    if (':' === $tokens[$j]) {+                        $skipClassToken = true;+                        break;+                    }+                    if (!\in_array($tokens[$j][0], [\T_WHITESPACE, \T_DOC_COMMENT, \T_COMMENT])) {+                        break;+                    }+                }                  if (!$skipClassToken) {                     $class = true;

@nlhommet
Copy link
ContributorAuthor

With this test I check if theT_CLASS token is after a comma or a parenthesis
This covers these 2 scenarios :

#[FooAttributes(    foo: [        'bar' => ['foo','bar'],        'foo'    ],    class: User::class)]
#[FooAttributes(    class: User::class,    foo: [        'bar' => ['foo','bar'],        'foo'    ])]

Normally it shouldn't have side effects

Copy link
Member

@derrabusderrabus left a comment

Choose a reason for hiding this comment

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

Please make fabbot happy. Apart from that, I think we're good. Thank you for working on this issue.

@nicolas-grekasnicolas-grekasforce-pushed theissue-40225/annotation-file-loader branch from27e6348 to27bba68CompareFebruary 22, 2021 15:26
@nicolas-grekas
Copy link
Member

Thank you@nlhommet.

@nicolas-grekasnicolas-grekas merged commit070f003 intosymfony:4.4Feb 22, 2021
This was referencedMar 4, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@derrabusderrabusderrabus approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

conflict with AnnotationFileLoader and PHP8 attributes

4 participants

@nlhommet@carsonbot@nicolas-grekas@derrabus

[8]ページ先頭

©2009-2025 Movatter.jp