From 4df57d63e6f2e9798c17c27bf972406baa6aedab Mon Sep 17 00:00:00 2001 From: Tobias Speicher Date: Mon, 21 Mar 2022 19:05:26 +0100 Subject: [PATCH 1/3] test: warn on substr() usage Don't allow any new substr() usage after #35421 Signed-off-by: Tobias Speicher --- .eslintrc.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 224a065e585b..498205341f68 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -203,7 +203,14 @@ "no-octal-escape": "warn", "no-redeclare": ["warn", { "builtinGlobals": false }], "no-regex-spaces": "warn", - "no-restricted-syntax": ["warn", "WithStatement"], + "no-restricted-syntax": [ + "warn", + "WithStatement", + { + "message": "substr is deprecated, use slice or substring instead", + "selector": "MemberExpression > Identifier[name='substr']" + } + ], "no-script-url": "warn", "no-self-assign": "warn", "no-self-compare": "warn", From 38debfa6eafccf95ad97977a1201d5c2151a2786 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 24 Mar 2022 17:50:12 -0400 Subject: [PATCH 2/3] Apply suggestions from code review --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 498205341f68..3f4f64868a1e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -207,7 +207,7 @@ "warn", "WithStatement", { - "message": "substr is deprecated, use slice or substring instead", + "message": "substr() is deprecated, use slice() or substring() instead", "selector": "MemberExpression > Identifier[name='substr']" } ], From 9c2755c3a71fc07323bfd26de11d0dfe0624561d Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 24 Mar 2022 18:01:51 -0400 Subject: [PATCH 3/3] Use slice in router-utils --- packages/next/server/router-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/server/router-utils.ts b/packages/next/server/router-utils.ts index 630521434fdb..c25ea5eeb572 100644 --- a/packages/next/server/router-utils.ts +++ b/packages/next/server/router-utils.ts @@ -3,7 +3,7 @@ export function replaceBasePath(pathname: string, basePath: string): string { // and doesn't contain extra chars e.g. basePath /docs // should replace for /docs, /docs/, /docs/a but not /docsss if (hasBasePath(pathname, basePath)) { - pathname = pathname.substr(basePath.length) + pathname = pathname.slice(basePath.length) if (!pathname.startsWith('/')) pathname = `/${pathname}` } return pathname