Skip to content

Commit c14063d

Browse files
committed
use regex to be more precise in href matching than just startsWith
1 parent 48638ad commit c14063d

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

middleware/contextualizers/current-product-tree.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ module.exports = function currentProductTree (req, res, next) {
44

55
const currentSiteTree = req.context.siteTree[req.context.currentLanguage][req.context.currentVersion]
66

7-
req.context.currentProductTree = currentSiteTree.childPages.find(page => req.context.currentPath.startsWith(page.href))
7+
req.context.currentProductTree = currentSiteTree.childPages.find(page => {
8+
// Find a product path that matches at least an initial part of the current path
9+
const regex = new RegExp(`^${page.href}($|\/)`, 'm')
10+
return regex.test(req.context.currentPath)
11+
})
812

913
return next()
1014
}

middleware/contextualizers/early-access-breadcrumbs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = async function breadcrumbs (req, res, next) {
22
if (!req.context.page) return next()
3-
if (!req.context.page.hidden) return next()
3+
if (!req.context.page.relativePath.startsWith('early-access')) return next()
44

55
req.context.breadcrumbs = []
66

middleware/contextualizers/generic-toc.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ module.exports = async function genericToc (req, res, next) {
2222
// Recursively loop through the siteTree until we reach the point where the
2323
// current siteTree page is the same as the requested page. Then stop.
2424
function findPageInSiteTree (pageArray, currentPath) {
25-
const childPage = pageArray.find(page => currentPath.startsWith(page.href))
25+
const childPage = pageArray.find(page => {
26+
// Find a page that matches at least an initial part of the current path
27+
const regex = new RegExp(`^${page.href}($|\/)`, 'm')
28+
return regex.test(currentPath)
29+
})
2630

2731
if (childPage.href === currentPath) {
2832
return childPage

0 commit comments

Comments
 (0)