Improve split handling. (#47)

This commit is contained in:
Felix Fontein 2021-09-09 22:19:57 +02:00 committed by GitHub
parent a88f4c804b
commit 48c7920072
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -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)."

View file

@ -321,12 +321,14 @@ class ROS_api_module:
self.where = None self.where = None
self.query = self.module.params['query'] self.query = self.module.params['query']
if self.query: if self.query:
if 'WHERE' in self.query: self.query = self.list_remove_empty(self.query.split(' '))
split = self.query.split('WHERE') try:
self.query = self.list_remove_empty(split[0].split(' ')) idx = self.query.index('WHERE')
self.where = self.list_remove_empty(split[1].split(' ')) self.where = self.query[idx + 1:]
else: self.query = self.query[:idx]
self.query = self.list_remove_empty(self.module.params['query'].split(' ')) except ValueError:
# Raised when WHERE has not been found
pass
self.result = dict( self.result = dict(
message=[]) message=[])
@ -358,7 +360,7 @@ class ROS_api_module:
for p in ldict: for p in ldict:
if '=' not in p: if '=' not in p:
self.errors("missing '=' after '%s'" % p) self.errors("missing '=' after '%s'" % p)
p = p.split('=') p = p.split('=', 1)
if p[1]: if p[1]:
dict[p[0]] = p[1] dict[p[0]] = p[1]
return dict return dict