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-25 20:11:13 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-25 20:11:13 +0300
commit241577f65eea94a08944bf096bd704b495282373 (patch)
tree81910ee1acbc13237cb2ee9ff61b2e315b499e86 /sphinx/themes
parentd6498f820987b1ed40225d505a94c7a2096bc5fd (diff)
parent3e479d772bbf084ccf1fa4f46af05e2762231e24 (diff)
Merge branch '8137_urldecode' into 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 6fc9e7f33..0dc528fb9 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})
}
}