aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2020-04-30 21:07:26 +0300
committerGitHub <[email protected]>2020-04-30 21:07:26 +0300
commit81404d2e3c8bf17de5570006376f1508e13c7b0e (patch)
tree561b579eaecd1bf3aac606d7fed1c903a0632fa5
parent3e73039936cac423919f8ccb260bc418ee83765e (diff)
downloadbootstrap-81404d2e3c8bf17de5570006376f1508e13c7b0e.tar.xz
bootstrap-81404d2e3c8bf17de5570006376f1508e13c7b0e.zip
search.js: make the check for URL stricter (#30695)
-rw-r--r--site/assets/js/search.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/site/assets/js/search.js b/site/assets/js/search.js
index ab57ad2f0..bb97c5cf8 100644
--- a/site/assets/js/search.js
+++ b/site/assets/js/search.js
@@ -35,14 +35,14 @@
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 = currentUrl.lastIndexOf(liveUrl, 0) === 0 ?
+ // On production, return the result as is
hit.url :
- hit.url.replace(liveUrl, '')
+ // 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, '/')
// Prevent jumping to first header
if (hit.anchor === 'content') {