From 3b23973c9d41886fce33253eba5bcdb0d19f1923 Mon Sep 17 00:00:00 2001 From: Santosh Bhattarai Date: Thu, 25 Jul 2024 19:44:00 +0545 Subject: [PATCH] chore: allow adding underscore (_), colon (:), comma (,), and dot(.) for the path and underscore (_) for path parameters --- .../awscloudformation/utils/rest-api-path-utils.test.ts | 2 +- .../awscloudformation/utils/rest-api-path-utils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/amplify-category-api/src/__tests__/provider-utils/awscloudformation/utils/rest-api-path-utils.test.ts b/packages/amplify-category-api/src/__tests__/provider-utils/awscloudformation/utils/rest-api-path-utils.test.ts index 6facce6d56..b7a1ae6893 100644 --- a/packages/amplify-category-api/src/__tests__/provider-utils/awscloudformation/utils/rest-api-path-utils.test.ts +++ b/packages/amplify-category-api/src/__tests__/provider-utils/awscloudformation/utils/rest-api-path-utils.test.ts @@ -27,7 +27,7 @@ test('validatePathName_hasTrailingSlash', () => { test('validatePathName_invalidCharacters', () => { // setup const errorMessage = - 'Each path part must use characters a-z A-Z 0-9 - and must not be empty.\nOptionally, a path part can be surrounded by { } to denote a path parameter.'; + 'Each path part must use characters a-z A-Z 0-9 - _ : , . and must not be empty.\nOptionally, a path part with characters a-z A-Z 0-9 - _ can be surrounded by { } to denote a path parameter.'; // test expect(validatePathName('/invalid+/{char}')).toStrictEqual(errorMessage); diff --git a/packages/amplify-category-api/src/provider-utils/awscloudformation/utils/rest-api-path-utils.ts b/packages/amplify-category-api/src/provider-utils/awscloudformation/utils/rest-api-path-utils.ts index b0ef42fde3..74ffe6aed7 100644 --- a/packages/amplify-category-api/src/provider-utils/awscloudformation/utils/rest-api-path-utils.ts +++ b/packages/amplify-category-api/src/provider-utils/awscloudformation/utils/rest-api-path-utils.ts @@ -20,8 +20,8 @@ export const validatePathName = (name: string) => { // Matches parameterized paths such as /book/{isbn}/page/{pageNum} // This regex also catches the above conditions, but those are left in to provide clearer error messages. - if (!/^(?:\/(?:[a-zA-Z0-9\-]+|{[a-zA-Z0-9\-]+}))+$/.test(name)) { - return 'Each path part must use characters a-z A-Z 0-9 - and must not be empty.\nOptionally, a path part can be surrounded by { } to denote a path parameter.'; + if (!/^(?:\/(?:[a-zA-Z0-9\-_:,.]+|{[a-zA-Z0-9\-_]+}))+$/.test(name)) { + return 'Each path part must use characters a-z A-Z 0-9 - _ : , . and must not be empty.\nOptionally, a path part with characters a-z A-Z 0-9 - _ can be surrounded by { } to denote a path parameter.'; } return true;