26
26
use Symfony \Component \HttpFoundation \Response ;
27
27
use Symfony \Component \HttpKernel \Attribute \Cache ;
28
28
use Symfony \Component \Routing \Attribute \Route ;
29
+ use Symfony \Component \Routing \Requirement \Requirement ;
29
30
use Symfony \Component \Security \Http \Attribute \CurrentUser ;
30
31
use Symfony \Component \Security \Http \Attribute \IsGranted ;
31
32
@@ -46,7 +47,7 @@ final class BlogController extends AbstractController
46
47
*/
47
48
#[Route('/ ' , name: 'blog_index ' , defaults: ['page ' => '1 ' , '_format ' => 'html ' ], methods: ['GET ' ])]
48
49
#[Route('/rss.xml ' , name: 'blog_rss ' , defaults: ['page ' => '1 ' , '_format ' => 'xml ' ], methods: ['GET ' ])]
49
- #[Route('/page/{page<[1-9]\d{0,8}>} ' , name: 'blog_index_paginated ' , defaults: ['_format ' => 'html ' ], methods: ['GET ' ])]
50
+ #[Route('/page/{page} ' , name: 'blog_index_paginated ' , defaults: ['_format ' => 'html ' ], requirements: [ ' page ' => Requirement:: POSITIVE_INT ], methods: ['GET ' ])]
50
51
#[Cache(smaxage: 10 )]
51
52
public function index (Request $ request , int $ page , string $ _format , PostRepository $ posts , TagRepository $ tags ): Response
52
53
{
@@ -74,7 +75,7 @@ public function index(Request $request, int $page, string $_format, PostReposito
74
75
*
75
76
* See https://symfony.com/doc/current/doctrine.html#automatically-fetching-objects-entityvalueresolver
76
77
*/
77
- #[Route('/posts/{slug} ' , name: 'blog_post ' , methods: ['GET ' ])]
78
+ #[Route('/posts/{slug} ' , name: 'blog_post ' , requirements: [ ' slug ' => Requirement:: ASCII_SLUG ], methods: ['GET ' ])]
78
79
public function postShow (Post $ post ): Response
79
80
{
80
81
// Symfony's 'dump()' function is an improved version of PHP's 'var_dump()' but
@@ -100,7 +101,7 @@ public function postShow(Post $post): Response
100
101
*
101
102
* See https://symfony.com/doc/current/doctrine.html#doctrine-entity-value-resolver
102
103
*/
103
- #[Route('/comment/{postSlug}/new ' , name: 'comment_new ' , methods: ['POST ' ])]
104
+ #[Route('/comment/{postSlug}/new ' , name: 'comment_new ' , requirements: [ ' postSlug ' => Requirement:: ASCII_SLUG ], methods: ['POST ' ])]
104
105
#[IsGranted('IS_AUTHENTICATED ' )]
105
106
public function commentNew (
106
107
#[CurrentUser] User $ user ,
0 commit comments