From bbc5c78ba11423d449db2d0d2cb4a1392f305ab3 Mon Sep 17 00:00:00 2001 From: A1lo Date: Wed, 27 Sep 2023 14:42:44 +0800 Subject: [PATCH] fix(url-check-locale): prevent replacing the empty url locale (#16157) --- scripts/check-url-locale.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/check-url-locale.js b/scripts/check-url-locale.js index acfba2f083507e..7fbc3b80174183 100644 --- a/scripts/check-url-locale.js +++ b/scripts/check-url-locale.js @@ -185,11 +185,14 @@ function fixUrlLocale(content, errors, expectedLocale) { } return a.line - b.line; }); + expectedLocale = `/${expectedLocale}/`; const lines = content.split("\n"); for (const { url, line, column, urlLocale } of errors) { let lineContent = lines[line - 1]; const prefix = lineContent.slice(0, column - 1); - const newUrl = url.replace(urlLocale, expectedLocale); + // replace the slashed locale with the expected locale + // to prevent replacing the empty url locale + const newUrl = url.replace(`/${urlLocale}/`, expectedLocale); const suffix = lineContent.slice(column - 1).replace(url, newUrl); lines[line - 1] = `${prefix}${suffix}`; } @@ -221,7 +224,7 @@ async function main() { spinner.text = "Crawling files..."; - const dryRun = argv.dry; + const dryRun = !argv.fix; for (const fp of argv.files) { const fstats = await fs.stat(fp);