Skip to content

Commit 2538a79

Browse files
authored
In old path redirects, freeze up sets we iterate over (#16916)
1 parent e427c36 commit 2538a79

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

lib/redirects/get-old-paths-from-permalink.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = function getOldPathsFromPath (currentPath, languageCode, curren
5656

5757
// ------ BEGIN MODERN VERSION FORMAT REPLACEMENTS ------//
5858
if (currentlySupportedVersions.includes(currentVersion) || versionSatisfiesRange(currentVersion, `>${lastReleaseWithLegacyFormat}`)) {
59-
oldPaths.forEach(oldPath => {
59+
(new Set(oldPaths)).forEach(oldPath => {
6060
// create old path /github from new path /free-pro-team@latest/github
6161
oldPaths.add(oldPath
6262
.replace(`/${nonEnterpriseDefaultVersion}`, ''))
@@ -107,19 +107,22 @@ module.exports = function getOldPathsFromPath (currentPath, languageCode, curren
107107
// ------ END MODERN VERSION FORMAT REPLACEMENTS ------//
108108

109109
// For each old path added to the set above, do the following...
110+
(new Set(oldPaths)).forEach(oldPath => {
111+
// for English only, remove language code
112+
if (languageCode === 'en') {
113+
oldPaths.add(getPathWithoutLanguage(oldPath))
114+
}
110115

111-
// add language code
112-
oldPaths.forEach(oldPath => oldPaths.add(getPathWithLanguage(oldPath, languageCode)))
116+
// add language code
117+
oldPaths.add(getPathWithLanguage(oldPath, languageCode))
113118

114-
// for English only, remove language code
115-
if (languageCode === 'en') {
116-
oldPaths.forEach(oldPath => oldPaths.add(getPathWithoutLanguage(oldPath)))
117-
}
119+
// create /enterprise from /enterprise/latest
120+
oldPaths.add(oldPath.replace(`/enterprise/${latest}`, '/enterprise'))
121+
})
118122

119-
// create /enterprise from /enterprise/latest
120-
oldPaths.forEach(oldPath => oldPaths.add(oldPath.replace(`/enterprise/${latest}`, '/enterprise')))
123+
// exclude any empty old paths that may have been derived
124+
oldPaths.delete('')
125+
oldPaths.delete('/')
121126

122-
return Array.from(oldPaths)
123-
// exclude any empty old paths that may have been derived
124-
.filter(oldPath => oldPath !== '' && oldPath !== '/')
127+
return oldPaths
125128
}

0 commit comments

Comments
 (0)