From 747f3ad8a7cfc5c46c25119182345c396c884276 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 21 Dec 2023 16:39:55 +0700 Subject: [PATCH 1/7] remove trailing slash in route --- src/ROUTES.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index ca1fe9f0e81a..32b7e915b10a 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -314,61 +314,61 @@ const ROUTES = { getRoute: (iouType: ValueOf, transactionID: string, reportID: string) => `create/${iouType}/start/${transactionID}/${reportID}` as const, }, MONEY_REQUEST_STEP_CONFIRMATION: { - route: 'create/:iouType/confirmation/:transactionID/:reportID/', + route: 'create/:iouType/confirmation/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string) => `create/${iouType}/confirmation/${transactionID}/${reportID}/` as const, }, MONEY_REQUEST_STEP_AMOUNT: { - route: 'create/:iouType/amount/:transactionID/:reportID/', + route: 'create/:iouType/amount/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/amount/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_CATEGORY: { - route: 'create/:iouType/category/:transactionID/:reportID/', + route: 'create/:iouType/category/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/category/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_CURRENCY: { - route: 'create/:iouType/currency/:transactionID/:reportID/:pageIndex?/', + route: 'create/:iouType/currency/:transactionID/:reportID/:pageIndex?', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, pageIndex = '', backTo = '') => getUrlWithBackToParam(`create/${iouType}/currency/${transactionID}/${reportID}/${pageIndex}`, backTo), }, MONEY_REQUEST_STEP_DATE: { - route: 'create/:iouType/date/:transactionID/:reportID/', + route: 'create/:iouType/date/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/date/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_DESCRIPTION: { - route: 'create/:iouType/description/:transactionID/:reportID/', + route: 'create/:iouType/description/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/description/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_DISTANCE: { - route: 'create/:iouType/distance/:transactionID/:reportID/', + route: 'create/:iouType/distance/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/distance/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_MERCHANT: { - route: 'create/:iouType/merchante/:transactionID/:reportID/', + route: 'create/:iouType/merchante/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/merchante/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_PARTICIPANTS: { - route: 'create/:iouType/participants/:transactionID/:reportID/', + route: 'create/:iouType/participants/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/participants/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_SCAN: { - route: 'create/:iouType/scan/:transactionID/:reportID/', + route: 'create/:iouType/scan/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/scan/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_TAG: { - route: 'create/:iouType/tag/:transactionID/:reportID/', + route: 'create/:iouType/tag/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/tag/${transactionID}/${reportID}/`, backTo), }, MONEY_REQUEST_STEP_WAYPOINT: { - route: 'create/:iouType/waypoint/:transactionID/:reportID/:pageIndex/', + route: 'create/:iouType/waypoint/:transactionID/:reportID/:pageIndex', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, pageIndex = '', backTo = '') => getUrlWithBackToParam(`create/${iouType}/waypoint/${transactionID}/${reportID}/${pageIndex}`, backTo), }, From 8a04fb11bb73c799133340feb031bce5cad197e8 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 22 Dec 2023 03:00:45 +0700 Subject: [PATCH 2/7] remove redundant slashes in route --- src/libs/Navigation/Navigation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index a3e89a983f98..85e4c0abb1cd 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -117,7 +117,7 @@ function getActiveRoute(): string { */ function isActiveRoute(routePath: Route): boolean { // We remove First forward slash from the URL before matching - return getActiveRoute().substring(1) === routePath; + return getActiveRoute().substring(1) === routePath.replace(/\/{2,}/, '/').replace(/\/$/, ''); } /** From e7e7762b6faa94896b9b4028369ebb417d2f5b20 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 22 Dec 2023 15:02:38 +0700 Subject: [PATCH 3/7] global regex to replace all rendundant slashes --- src/libs/Navigation/Navigation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 85e4c0abb1cd..657ee68b1206 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -117,7 +117,7 @@ function getActiveRoute(): string { */ function isActiveRoute(routePath: Route): boolean { // We remove First forward slash from the URL before matching - return getActiveRoute().substring(1) === routePath.replace(/\/{2,}/, '/').replace(/\/$/, ''); + return getActiveRoute().substring(1) === routePath.replace(/\/{2,}/g, '/').replace(/\/$/, ''); } /** From 1bdc86667e1e097e64ec323420ff54ffcc6fc128 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 27 Dec 2023 15:06:41 +0700 Subject: [PATCH 4/7] add regex to CONST --- src/CONST.ts | 1 + src/libs/Navigation/Navigation.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 812fb4d5335d..3527902dff40 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1406,6 +1406,7 @@ const CONST = { ROUTES: { VALIDATE_LOGIN: /\/v($|(\/\/*))/, UNLINK_LOGIN: /\/u($|(\/\/*))/, + REDUNDANT_SLASHES: /(\/{2,})|(\/$)/g, }, TIME_STARTS_01: /^01:\d{2} [AP]M$/, diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index e62b2e057d44..d1c6459a8aee 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -114,8 +114,9 @@ function getActiveRoute(): string { * @return is active */ function isActiveRoute(routePath: Route): boolean { - // We remove First forward slash from the URL before matching - return getActiveRoute().substring(1) === routePath.replace(/\/{2,}/g, '/').replace(/\/$/, ''); + // We remove First forward slash from the URL + // And redundant (consecutive and trailing) slashes from path before matching + return getActiveRoute().substring(1) === routePath.replace(CONST.REGEX.ROUTES.REDUNDANT_SLASHES, (_, p1) => (p1 ? '/' : '')); } /** From fa4a8e442b22ff07c518d443549bca5861860480 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 27 Dec 2023 15:41:04 +0700 Subject: [PATCH 5/7] fix lint --- src/libs/Navigation/Navigation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index d1c6459a8aee..bc8c998a9f87 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -116,7 +116,7 @@ function getActiveRoute(): string { function isActiveRoute(routePath: Route): boolean { // We remove First forward slash from the URL // And redundant (consecutive and trailing) slashes from path before matching - return getActiveRoute().substring(1) === routePath.replace(CONST.REGEX.ROUTES.REDUNDANT_SLASHES, (_, p1) => (p1 ? '/' : '')); + return getActiveRoute().substring(1) === routePath.replace(CONST.REGEX.ROUTES.REDUNDANT_SLASHES, (match, p1) => (p1 ? '/' : '')); } /** From eec02f92868354c5d9786726964607fa4981e6e2 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 3 Jan 2024 14:58:53 +0700 Subject: [PATCH 6/7] remove trailing slash from getRoute --- src/ROUTES.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 90c0114eaa56..a720c526b58d 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -315,17 +315,17 @@ const ROUTES = { }, MONEY_REQUEST_STEP_CONFIRMATION: { route: 'create/:iouType/confirmation/:transactionID/:reportID', - getRoute: (iouType: ValueOf, transactionID: string, reportID: string) => `create/${iouType}/confirmation/${transactionID}/${reportID}/` as const, + getRoute: (iouType: ValueOf, transactionID: string, reportID: string) => `create/${iouType}/confirmation/${transactionID}/${reportID}` as const, }, MONEY_REQUEST_STEP_AMOUNT: { route: 'create/:iouType/amount/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/amount/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/amount/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_CATEGORY: { route: 'create/:iouType/category/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/category/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/category/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_CURRENCY: { route: 'create/:iouType/currency/:transactionID/:reportID/:pageIndex?', @@ -335,37 +335,37 @@ const ROUTES = { MONEY_REQUEST_STEP_DATE: { route: 'create/:iouType/date/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/date/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/date/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_DESCRIPTION: { route: 'create/:iouType/description/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/description/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/description/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_DISTANCE: { route: 'create/:iouType/distance/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/distance/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/distance/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_MERCHANT: { route: 'create/:iouType/merchante/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/merchante/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/merchante/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_PARTICIPANTS: { route: 'create/:iouType/participants/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/participants/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/participants/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_SCAN: { route: 'create/:iouType/scan/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/scan/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/scan/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_TAG: { route: 'create/:iouType/tag/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/tag/${transactionID}/${reportID}/`, backTo), + getUrlWithBackToParam(`create/${iouType}/tag/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_WAYPOINT: { route: 'create/:iouType/waypoint/:transactionID/:reportID/:pageIndex', From 56f2445f4281752405226ab6d1fe692c08631fe2 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 8 Jan 2024 10:09:43 +0700 Subject: [PATCH 7/7] revert redundant changes --- src/ROUTES.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index c845a6dc11b4..e8a860582bb1 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -323,7 +323,7 @@ const ROUTES = { getUrlWithBackToParam(`create/${iouType}/amount/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_TAX_RATE: { - route: 'create/:iouType/taxRate/:transactionID/:reportID', + route: 'create/:iouType/taxRate/:transactionID/:reportID?', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo: string) => getUrlWithBackToParam(`create/${iouType}/taxRate/${transactionID}/${reportID}`, backTo), }, @@ -333,7 +333,7 @@ const ROUTES = { getUrlWithBackToParam(`create/${iouType}/taxAmount/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_CATEGORY: { - route: 'create/:iouType/category/:transactionID/:reportID?', + route: 'create/:iouType/category/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => getUrlWithBackToParam(`create/${iouType}/category/${transactionID}/${reportID}`, backTo), },