Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-27 18:56:46 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-27 18:56:46 +0300
commitc9480f99433a660942cbd8a739d989cb69fedc36 (patch)
treea5861ecf723184f5a7e6e89ba14433867f2d5e4f /sphinx/themes
parent2ee0338388a54e976c3776c116cdc1080fb62c53 (diff)
parent62dad2f13331d15d94b36b8f125f08fd4304b68b (diff)
Merge branch '3.x'
Diffstat (limited to 'sphinx/themes')
-rw-r--r--sphinx/themes/basic/static/doctools.js7
-rw-r--r--sphinx/themes/basic/static/searchtools.js12
2 files changed, 16 insertions, 3 deletions
diff --git a/sphinx/themes/basic/static/doctools.js b/sphinx/themes/basic/static/doctools.js
index 144884ea6..61ac9d266 100644
--- a/sphinx/themes/basic/static/doctools.js
+++ b/sphinx/themes/basic/static/doctools.js
@@ -29,9 +29,14 @@ if (!window.console || !console.firebug) {
/**
* small helper function to urldecode strings
+ *
+ * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL
*/
jQuery.urldecode = function(x) {
- return decodeURIComponent(x).replace(/\+/g, ' ');
+ if (!x) {
+ return x
+ }
+ return decodeURIComponent(x.replace(/\+/g, ' '));
};
/**
diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js
index 2cb28b330..847e879d2 100644
--- a/sphinx/themes/basic/static/searchtools.js
+++ b/sphinx/themes/basic/static/searchtools.js
@@ -380,6 +380,13 @@ var Search = {
},
/**
+ * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
+ */
+ escapeRegExp : function(string) {
+ return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
+ },
+
+ /**
* search for full-text terms in the index
*/
performTermsSearch : function(searchterms, excluded, terms, titleterms) {
@@ -402,13 +409,14 @@ var Search = {
];
// add support for partial matches
if (word.length > 2) {
+ var word_regex = this.escapeRegExp(word);
for (var w in terms) {
- if (w.match(word) && !terms[word]) {
+ if (w.match(word_regex) && !terms[word]) {
_o.push({files: terms[w], score: Scorer.partialTerm})
}
}
for (var w in titleterms) {
- if (w.match(word) && !titleterms[word]) {
+ if (w.match(word_regex) && !titleterms[word]) {
_o.push({files: titleterms[w], score: Scorer.partialTitle})
}
}