2626use Symfony \Component \HttpFoundation \Response ;
2727use Symfony \Component \HttpKernel \Attribute \Cache ;
2828use Symfony \Component \Routing \Attribute \Route ;
29+ use Symfony \Component \Routing \Requirement \Requirement ;
2930use Symfony \Component \Security \Http \Attribute \CurrentUser ;
3031use Symfony \Component \Security \Http \Attribute \IsGranted ;
3132
@@ -46,7 +47,7 @@ final class BlogController extends AbstractController
4647 */
4748 #[Route('/ ' , name: 'blog_index ' , defaults: ['page ' => '1 ' , '_format ' => 'html ' ], methods: ['GET ' ])]
4849 #[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 ' ])]
5051 #[Cache(smaxage: 10 )]
5152 public function index (Request $ request , int $ page , string $ _format , PostRepository $ posts , TagRepository $ tags ): Response
5253 {
@@ -74,7 +75,7 @@ public function index(Request $request, int $page, string $_format, PostReposito
7475 *
7576 * See https://symfony.com/doc/current/doctrine.html#automatically-fetching-objects-entityvalueresolver
7677 */
77- #[Route('/posts/{slug} ' , name: 'blog_post ' , methods: ['GET ' ])]
78+ #[Route('/posts/{slug} ' , name: 'blog_post ' , requirements: [ ' slug ' => Requirement:: ASCII_SLUG ], methods: ['GET ' ])]
7879 public function postShow (Post $ post ): Response
7980 {
8081 // Symfony's 'dump()' function is an improved version of PHP's 'var_dump()' but
@@ -100,7 +101,7 @@ public function postShow(Post $post): Response
100101 *
101102 * See https://symfony.com/doc/current/doctrine.html#doctrine-entity-value-resolver
102103 */
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 ' ])]
104105 #[IsGranted('IS_AUTHENTICATED ' )]
105106 public function commentNew (
106107 #[CurrentUser] User $ user ,
0 commit comments