From cf31a03c3298adbb2dfc13ad6e496b48e2f20269 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 24 Oct 2021 21:14:27 +0200 Subject: [PATCH] Catch edge cases were delimiters are wrongfully caught --- lib/cheat_wrapper.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/cheat_wrapper.py b/lib/cheat_wrapper.py index 59e6b92..606f351 100644 --- a/lib/cheat_wrapper.py +++ b/lib/cheat_wrapper.py @@ -26,9 +26,25 @@ def _add_section_name(query): if '/' in query: return query if ' ' in query: - # for standalone queries only that may contain ' ' - return "%s/%s" % tuple(query.split(' ', 1)) - return "%s/%s" % tuple(query.split('+', 1)) + delim = " " + elif '+' in query: + delim = "+" + + index = 0 + length = len(query) + while index != length: + + index = query.index(delim, index) + 1 + + try: + comparison = query.index(delim, index) + except ValueError: + comparison = -1 + + if (index != comparison and index != length): + return "%s/%s" % (query[:index-1], query[index:]) + + return query def cheat_wrapper(query, request_options=None, output_format='ansi'): """