@@ -78,30 +78,22 @@ public static function fromRawCookie(string $rawCookie): self
7878 if (!str_contains ($ rawCookie , self ::COOKIE_DELIMITER )) {
7979 $ rawCookie = base64_decode ($ rawCookie );
8080 }
81- $ cookieParts = explode (self ::COOKIE_DELIMITER , $ rawCookie , 3 );
8281
83- if (isset ($ cookieParts [1 ]) && !preg_match ('/^\d+$/ ' , $ cookieParts [1 ])) {
84- // legacy (Symfony < 8.0) cookie format
85- $ cookieParts = explode (self ::COOKIE_DELIMITER , $ rawCookie , 4 );
82+ $ cookieParts = explode (self ::COOKIE_DELIMITER , $ rawCookie , 4 );
8683
87- if (4 !== \count ($ cookieParts )) {
88- throw new AuthenticationException ('The cookie contains invalid data. ' );
89- }
84+ if (4 !== \count ($ cookieParts )) {
85+ throw new AuthenticationException ('The cookie contains invalid data. ' );
86+ }
9087
91- if (false === $ cookieParts [1 ] = base64_decode (strtr ($ cookieParts [1 ], '-_~ ' , '+/= ' ), true )) {
92- throw new AuthenticationException ('The user identifier contains a character from outside the base64 alphabet. ' );
93- }
88+ if (false === $ cookieParts [1 ] = base64_decode (strtr ($ cookieParts [1 ], '-_~ ' , '+/= ' ), true )) {
89+ throw new AuthenticationException ('The user identifier contains a character from outside the base64 alphabet. ' );
90+ }
9491
92+ if ('' === $ cookieParts [0 ]) {
93+ unset($ cookieParts [0 ]);
94+ } else {
9595 $ cookieParts [0 ] = strtr ($ cookieParts [0 ], '. ' , '\\' );
9696 $ cookieParts [4 ] = false ;
97- } else {
98- if (3 !== \count ($ cookieParts )) {
99- throw new AuthenticationException ('The cookie contains invalid data. ' );
100- }
101-
102- if (false === $ cookieParts [0 ] = base64_decode (strtr ($ cookieParts [0 ], '-_~ ' , '+/= ' ), true )) {
103- throw new AuthenticationException ('The user identifier contains a character from outside the base64 alphabet. ' );
104- }
10597 }
10698
10799 return new static (...$ cookieParts );
0 commit comments