Skip to content

Commit

Permalink
test: warn on substr() usage (#35499)
Browse files Browse the repository at this point in the history
* test: warn on substr() usage

Don't allow any new substr() usage after #35421

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>

* Apply suggestions from code review

* Use slice in router-utils

Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
CommanderRoot and styfle committed Mar 24, 2022
1 parent db2567b commit b21e3c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/router-utils.ts
Expand Up @@ -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
Expand Down

0 comments on commit b21e3c2

Please sign in to comment.