From 9ad1c1a332c4ad4c8a85fd1064fdcdbf3fbb6eaa Mon Sep 17 00:00:00 2001 From: Ivan Starkov Date: Tue, 8 Oct 2024 11:49:52 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20Publish=20crashes=20on=20pages=20with=20?= =?UTF-8?q?dynamic=20paths=20ending=20in=20=E2=80=98=3F=E2=80=99=20(#4248)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description ref #4247 image ## Steps for reproduction see tests ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file --- apps/builder/app/builder/shared/url-pattern.test.ts | 6 ++++++ apps/builder/app/builder/shared/url-pattern.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/apps/builder/app/builder/shared/url-pattern.test.ts b/apps/builder/app/builder/shared/url-pattern.test.ts index a0157cdba2..2b450a16e2 100644 --- a/apps/builder/app/builder/shared/url-pattern.test.ts +++ b/apps/builder/app/builder/shared/url-pattern.test.ts @@ -216,3 +216,9 @@ test(`forbid named group with static parts before or after`, () => { `Static parts cannot be mixed with dynamic parameters at 'prefix-:id-suffix'.`, ]); }); + +test(`? should be allowed in named groups only`, () => { + expect(validatePathnamePattern("/name?")).toEqual([ + `Optional parameter indicator ? must be at the end of the named parameter. Correct usage: /:param?`, + ]); +}); diff --git a/apps/builder/app/builder/shared/url-pattern.ts b/apps/builder/app/builder/shared/url-pattern.ts index 6598eae203..996e0c6c33 100644 --- a/apps/builder/app/builder/shared/url-pattern.ts +++ b/apps/builder/app/builder/shared/url-pattern.ts @@ -147,6 +147,10 @@ export const validatePathnamePattern = (pathname: string) => { `Static parts cannot be mixed with dynamic parameters at '${segment}'.` ); } + } else if (segment.includes("?")) { + messages.push( + `Optional parameter indicator ? must be at the end of the named parameter. Correct usage: /:param?` + ); } }