escape special chars in variable name (fix #225)

This commit is contained in:
ziirish 2018-01-05 23:40:21 +01:00
parent e2f9910f35
commit 662e5e2f24
No known key found for this signature in database
GPG key ID: 72DB229A64B54E46
2 changed files with 8 additions and 2 deletions

View file

@ -7,6 +7,7 @@
.. moduleauthor:: Ziirish <hi+burpui@ziirish.me>
"""
import re
import math
import uuid
@ -62,6 +63,11 @@ def bytes_human(value):
return '{0:.1eM}'.format(_hr(value))
@view.app_template_filter()
def regex_replace(value, regex, replace):
"""Replace every string matching the given regex with the replacement"""
return re.sub(regex, replace, value, flags=re.IGNORECASE)
"""
And here is the main site
"""

View file

@ -263,7 +263,7 @@ $.get("{{ url_for('api.clients_all') }}")
{% for srv in config.SERVERS %}
var _clients_{{ srv }} = [];
var _clients_{{ srv|regex_replace("[^a-z0-9_]", "_") }} = [];
{% endfor %}
@ -283,7 +283,7 @@ $('#input-client').typeahead({
{
name: '{{ srv }}',
displayKey: 'name',
source: substringMatcher(_clients_{{ srv }}),
source: substringMatcher(_clients_{{ srv|regex_replace("[^a-z0-9_]", "_") }}),
templates: {
header: '<h3 class="server-name">{{ srv }}</h3>'
}