From 0fa9cf334ec00a1f0df767ed4bfdea54bd604237 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 30 Apr 2020 11:01:35 +0300 Subject: [PATCH 1/4] search.js: make the check for URL stricter --- site/assets/js/search.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/site/assets/js/search.js b/site/assets/js/search.js index ab57ad2f0030..64f4ce6ed718 100644 --- a/site/assets/js/search.js +++ b/site/assets/js/search.js @@ -35,14 +35,15 @@ transformData: function (hits) { return hits.map(function (hit) { var currentUrl = getOrigin() - var liveUrl = 'https://getbootstrap.com' + var liveUrl = /^https?:\/\/getbootstrap\.com\// // When in production, return the result as is, // otherwise remove our url from it. - // eslint-disable-next-line no-negated-condition - hit.url = currentUrl.indexOf(liveUrl) !== -1 ? // lgtm [js/incomplete-url-substring-sanitization] + hit.url = liveUrl.test(currentUrl) ? hit.url : - hit.url.replace(liveUrl, '') + // replace the URL with a trailing slash, so that + // `hit.url` is relative to server root on development + hit.url.replace(liveUrl, '/') // Prevent jumping to first header if (hit.anchor === 'content') { From 2cc38ba87dd6ba12bcf1d7067380d900899c0e24 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 30 Apr 2020 11:12:35 +0300 Subject: [PATCH 2/4] Solution with `lastIndexOf` --- site/assets/js/search.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/assets/js/search.js b/site/assets/js/search.js index 64f4ce6ed718..c226a77619f6 100644 --- a/site/assets/js/search.js +++ b/site/assets/js/search.js @@ -35,11 +35,11 @@ transformData: function (hits) { return hits.map(function (hit) { var currentUrl = getOrigin() - var liveUrl = /^https?:\/\/getbootstrap\.com\// + var liveUrl = 'https://getbootstrap.com/' // When in production, return the result as is, // otherwise remove our url from it. - hit.url = liveUrl.test(currentUrl) ? + hit.url = currentUrl.lastIndexOf(liveUrl, 0) === 0 ? hit.url : // replace the URL with a trailing slash, so that // `hit.url` is relative to server root on development From 05568d015a9f5d800966f9936323e95b5aeac6bf Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 30 Apr 2020 11:57:45 +0300 Subject: [PATCH 3/4] Update search.js --- site/assets/js/search.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/site/assets/js/search.js b/site/assets/js/search.js index c226a77619f6..4604626d3155 100644 --- a/site/assets/js/search.js +++ b/site/assets/js/search.js @@ -37,12 +37,11 @@ var currentUrl = getOrigin() var liveUrl = 'https://getbootstrap.com/' - // When in production, return the result as is, - // otherwise remove our url from it. hit.url = currentUrl.lastIndexOf(liveUrl, 0) === 0 ? + // When in production, return the result as is hit.url : - // replace the URL with a trailing slash, so that - // `hit.url` is relative to server root on development + // When in development, replace `hit.url` with a trailing slash, + // so that the result link is relative to the server root hit.url.replace(liveUrl, '/') // Prevent jumping to first header From fd6899c92e7c1928e24dbef400ac0768c2898a57 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 30 Apr 2020 21:01:20 +0300 Subject: [PATCH 4/4] Update search.js --- site/assets/js/search.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/assets/js/search.js b/site/assets/js/search.js index 4604626d3155..bb97c5cf80c1 100644 --- a/site/assets/js/search.js +++ b/site/assets/js/search.js @@ -38,9 +38,9 @@ var liveUrl = 'https://getbootstrap.com/' hit.url = currentUrl.lastIndexOf(liveUrl, 0) === 0 ? - // When in production, return the result as is + // On production, return the result as is hit.url : - // When in development, replace `hit.url` with a trailing slash, + // On development or Netlify, replace `hit.url` with a trailing slash, // so that the result link is relative to the server root hit.url.replace(liveUrl, '/')