Inlined regex escaping from dependency

This commit is contained in:
squidfunk 2019-04-17 10:40:41 +02:00
parent 13a4c9172d
commit 185147684c
9 changed files with 242 additions and 1175 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -66,7 +66,7 @@
{% endif %}
{% endblock %}
{% block libs %}
<script src="{{ 'assets/javascripts/modernizr.1f0bcf2b.js' | url }}"></script>
<script src="{{ 'assets/javascripts/modernizr.74668098.js' | url }}"></script>
{% endblock %}
{% block fonts %}
{% if font != false %}
@ -190,7 +190,7 @@
{% endblock %}
</div>
{% block scripts %}
<script src="{{ 'assets/javascripts/application.3ca04de7.js' | url }}"></script>
<script src="{{ 'assets/javascripts/application.48c2c9de.js' | url }}"></script>
{% if lang.t("search.language") != "en" %}
{% set languages = lang.t("search.language").split(",") %}
{% if languages | length and languages[0] != "" %}

1388
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,6 @@
"cssmin": "^0.4.3",
"custom-event-polyfill": "^1.0.7",
"customizr": "^1.2.1",
"escape-string-regexp": "^1.0.5",
"eslint": "^5.16.0",
"event-hooks-webpack-plugin": "^2.1.1",
"expose-loader": "^0.7.4",

View File

@ -20,13 +20,25 @@
* IN THE SOFTWARE.
*/
import escape from "escape-string-regexp"
import lunr from "expose-loader?lunr!lunr"
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Escape a regular expression string
*
* Taken from the package `escape-string-regexp`
*
* @param regex - Regular expresison string
*
* @return
*/
const escapeRegex = regex => {
return regex.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&');
};
/**
* Escape HTML strings
*
@ -291,7 +303,7 @@ export default class Result {
}, new Map)
/* Assemble regular expressions for matching */
const query = escape(this.value_.trim()).replace(
const query = escapeRegex(this.value_.trim()).replace(
new RegExp(lunr.tokenizer.separator, "img"), "|")
const match =
new RegExp(`(^|${lunr.tokenizer.separator})(${query})`, "img")