Skip to content

Commit

Permalink
Improve split handling. (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Sep 9, 2021
1 parent a88f4c8 commit 48c7920
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/47-api-split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- "api - improve splitting of ``WHERE`` queries (https://github.com/ansible-collections/community.routeros/pull/47)."
- "api - when converting result lists to dictionaries, no longer removes second ``=`` and text following that if present (https://github.com/ansible-collections/community.routeros/pull/47)."
16 changes: 9 additions & 7 deletions plugins/modules/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,14 @@ def __init__(self):
self.where = None
self.query = self.module.params['query']
if self.query:
if 'WHERE' in self.query:
split = self.query.split('WHERE')
self.query = self.list_remove_empty(split[0].split(' '))
self.where = self.list_remove_empty(split[1].split(' '))
else:
self.query = self.list_remove_empty(self.module.params['query'].split(' '))
self.query = self.list_remove_empty(self.query.split(' '))
try:
idx = self.query.index('WHERE')
self.where = self.query[idx + 1:]
self.query = self.query[:idx]
except ValueError:
# Raised when WHERE has not been found
pass

self.result = dict(
message=[])
Expand Down Expand Up @@ -358,7 +360,7 @@ def list_to_dic(self, ldict):
for p in ldict:
if '=' not in p:
self.errors("missing '=' after '%s'" % p)
p = p.split('=')
p = p.split('=', 1)
if p[1]:
dict[p[0]] = p[1]
return dict
Expand Down

0 comments on commit 48c7920

Please sign in to comment.