diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-01-25 20:11:13 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-01-25 20:11:13 +0300 |
commit | 241577f65eea94a08944bf096bd704b495282373 (patch) | |
tree | 81910ee1acbc13237cb2ee9ff61b2e315b499e86 /sphinx/themes | |
parent | d6498f820987b1ed40225d505a94c7a2096bc5fd (diff) | |
parent | 3e479d772bbf084ccf1fa4f46af05e2762231e24 (diff) |
Merge branch '8137_urldecode' into 3.x
Diffstat (limited to 'sphinx/themes')
-rw-r--r-- | sphinx/themes/basic/static/doctools.js | 7 | ||||
-rw-r--r-- | sphinx/themes/basic/static/searchtools.js | 12 |
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}) } } |