From a26e5002a308b284e0208e173f3e7a855be226cc Mon Sep 17 00:00:00 2001 From: Mike McNeil Date: Mon, 25 Jul 2022 11:16:40 -0500 Subject: [PATCH] Website: Follow up to strip leading slashes (#6843) * Website: Follow up to strip leading slashes re https://github.com/fleetdm/fleet/pull/6796#issuecomment-1193054810 * remove log * Verified: whitespace trim not needed And leading slash trim is only needed if using a regex route (not something I recommend most of the time). But since we are using one, I included it, and put it in all three places for consistency. (It doesn't ever hurt) --- website/api/controllers/articles/view-basic-article.js | 4 ++-- website/api/controllers/docs/view-basic-documentation.js | 4 ++-- website/api/controllers/handbook/view-basic-handbook.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/website/api/controllers/articles/view-basic-article.js b/website/api/controllers/articles/view-basic-article.js index f07f677928..2fdc749792 100644 --- a/website/api/controllers/articles/view-basic-article.js +++ b/website/api/controllers/articles/view-basic-article.js @@ -35,8 +35,8 @@ module.exports = { // Serve appropriate page content. let thisPage = _.find(sails.config.builtStaticContent.markdownPages, { url: '/' + pageUrlSuffix }); - if (!thisPage) {// If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with internal slashes deduped, and any trailing slash or whitespace trimmed - let revisedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(/\/+/g, '/').replace(/\/+\s*$/,''); + if (!thisPage) {// If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with all slashes deduped, and any leading or trailing slash removed (leading slashes are only possible if this is a regex, rather than "/*" route) + let revisedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(/\/+/g, '/').replace(/^\/+/,'').replace(/\/+$/,''); thisPage = _.find(sails.config.builtStaticContent.markdownPages, { url: '/' + revisedPageUrlSuffix }); if (thisPage) {// If we matched a page with the revised suffix, then redirect to that rather than rendering it, so the URL gets cleaned up. throw {redirect: thisPage.url}; diff --git a/website/api/controllers/docs/view-basic-documentation.js b/website/api/controllers/docs/view-basic-documentation.js index 629060dfc6..a6a64ae0a4 100644 --- a/website/api/controllers/docs/view-basic-documentation.js +++ b/website/api/controllers/docs/view-basic-documentation.js @@ -45,8 +45,8 @@ module.exports = { : SECTION_URL_PREFIX + '/' + pageUrlSuffix// « individual content page ) }); - if (!thisPage) {// If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with internal slashes deduped, and any trailing slash or whitespace trimmed - let revisedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(/\/+/g, '/').replace(/^\/+\s*|\/+\s*$/,''); + if (!thisPage) {// If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with all slashes deduped, and any leading or trailing slash removed (leading slashes are only possible if this is a regex, rather than "/*" route) + let revisedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(/\/+/g, '/').replace(/^\/+/,'').replace(/\/+$/,''); thisPage = _.find(sails.config.builtStaticContent.markdownPages, { url: SECTION_URL_PREFIX + '/' + revisedPageUrlSuffix }); if (thisPage) {// If we matched a page with the revised suffix, then redirect to that rather than rendering it, so the URL gets cleaned up. throw {redirect: thisPage.url}; diff --git a/website/api/controllers/handbook/view-basic-handbook.js b/website/api/controllers/handbook/view-basic-handbook.js index c193d53f93..2a05af2ab4 100644 --- a/website/api/controllers/handbook/view-basic-handbook.js +++ b/website/api/controllers/handbook/view-basic-handbook.js @@ -45,8 +45,8 @@ module.exports = { : SECTION_URL_PREFIX + '/' + pageUrlSuffix// « individual content page ) }); - if (!thisPage) {// If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with internal slashes deduped, and any trailing slash or whitespace trimmed - let revisedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(/\/+/g, '/').replace(/^\/+\s*|\/+\s*$/,''); + if (!thisPage) {// If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with all slashes deduped, and any leading or trailing slash removed (leading slashes are only possible if this is a regex, rather than "/*" route) + let revisedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(/\/+/g, '/').replace(/^\/+/,'').replace(/\/+$/,''); thisPage = _.find(sails.config.builtStaticContent.markdownPages, { url: SECTION_URL_PREFIX + '/' + revisedPageUrlSuffix }); if (thisPage) {// If we matched a page with the revised suffix, then redirect to that rather than rendering it, so the URL gets cleaned up. throw {redirect: thisPage.url};