Module: check_mk
Branch: master
Commit: d0aaec09ab280faa569c356e886392bbefb84107
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d0aaec09ab280f…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Jun 20 14:06:09 2017 +0200
4834 FIX Quicksearch: fixed quoting problem with \ in service description
Change-Id: I67ff6177c241f9ce8b18044c6230d82731f305d3
---
.werks/4834 | 10 ++++++++++
web/htdocs/sidebar.py | 49 ++++++++++++++++++++++++++++++-------------------
2 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/.werks/4834 b/.werks/4834
new file mode 100644
index 0000000..3be150e
--- /dev/null
+++ b/.werks/4834
@@ -0,0 +1,10 @@
+Title: Quicksearch: fixed quoting problem with \ in service description
+Level: 1
+Component: multisite
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1497960330
+Class: fix
+
+
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index d5351a9..bce5777 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -745,8 +745,20 @@ def search_open():
html.http_redirect(url)
+
+class LivestatusSearchBase(object):
+ def _build_url(self, url_params, restore_regex = False):
+ new_params = []
+ if restore_regex:
+ for key, value in url_params:
+ new_params.append((key, value.replace("\\",
"\\\\")))
+ else:
+ new_params.extend(url_params)
+ return html.makeuri(new_params, delvars = "q", filename =
"view.py")
+
+
# Handles exactly one livestatus query
-class LivestatusSearchConductor(object):
+class LivestatusSearchConductor(LivestatusSearchBase):
def __init__(self, used_filters, filter_behaviour):
# used_filters: {u'h': [u'heute'], u's':
[u'Check_MK']}
# filter_behaviour: "continue"
@@ -896,11 +908,11 @@ class LivestatusSearchConductor(object):
} [self._livestatus_table]
- def get_search_url(self):
+ def get_search_url_params(self):
exact_match = self.num_rows() == 1
target_view = self._get_target_view(exact_match = exact_match)
- url_params = []
+ url_params = [("view_name", target_view), ("filled_in",
"filter")]
for plugin in self._used_search_plugins:
match_info = plugin.get_matches(target_view,
exact_match and self._rows[0] or None,
@@ -912,10 +924,7 @@ class LivestatusSearchConductor(object):
text, url_filters = match_info
url_params.extend(url_filters)
- return html.makeuri([("view_name", target_view),
- ("filled_in", "filter")] + url_params,
- delvars = "q",
- filename = "view.py")
+ return url_params
def create_result_elements(self):
@@ -939,10 +948,9 @@ class LivestatusSearchConductor(object):
url_params.extend(url_filters)
entry["text_tokens"].append((plugin.get_filter_shortname(),
text))
- entry["url"] = html.makeuri([("view_name",
target_view),
- ("site",
row.get("site"))] + url_params,
- delvars = "q",
- filename = "view.py")
+ entry["url"] = self._build_url([("view_name",
target_view),
+ ("site",
row.get("site"))] + url_params, restore_regex = True)
+
entry["raw_data"] = row
self._elements.append(entry)
@@ -1020,7 +1028,7 @@ class LivestatusSearchConductor(object):
-class LivestatusQuicksearch(object):
+class LivestatusQuicksearch(LivestatusSearchBase):
def __init__(self, query):
self._query = query
self._search_objects = [] # Each of these objects do exactly one ls query
@@ -1037,18 +1045,21 @@ class LivestatusQuicksearch(object):
self._query_data()
# Generate a search page for the topmost search_object with results
- search_object = None
+ url_params = []
+
+ restore_regex = False
for search_object in self._search_objects:
if search_object.num_rows() > 0:
- use_search_object = search_object
+ url_params.extend(search_object.get_search_url_params())
+ if search_object.num_rows() == 1:
+ restore_regex = True
break
else:
- return html.makeuri([("view_name", "allservices"),
- ("filled_in", "filter"),
("service_regex", self._query)],
- delvars = "q",
- filename = "view.py")
+ url_params.extend([("view_name", "allservices"),
+ ("filled_in", "filter"),
+ ("service_regex", self._query)])
- return search_object.get_search_url()
+ return self._build_url(url_params, restore_regex = restore_regex)
def _query_data(self):