changeset 2763:c4190d5340ab

XEP-0059: max value check: check that max is not negative, this is to spot the accidental use of C.NO_LIMIT for max
author Goffi <goffi@goffi.org>
date Fri, 11 Jan 2019 09:48:19 +0100
parents 5a51c7fc74a5
children 92af49cde255
files sat/plugins/plugin_xep_0059.py sat/plugins/plugin_xep_0313.py
diffstat 2 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0059.py	Fri Jan 11 09:48:17 2019 +0100
+++ b/sat/plugins/plugin_xep_0059.py	Fri Jan 11 09:48:19 2019 +0100
@@ -61,6 +61,9 @@
         @return (rsm.RSMRequest, None): request with parsed arguments
             or None if no RSM arguments have been found
         """
+        if int(extra.get(RSM_PREFIX + u'max', 0)) < 0:
+            raise ValueError(_(u"rsm_max can't be negative"))
+
         rsm_args = {}
         for arg in (u"max", u"after", u"before", u"index"):
             try:
--- a/sat/plugins/plugin_xep_0313.py	Fri Jan 11 09:48:17 2019 +0100
+++ b/sat/plugins/plugin_xep_0313.py	Fri Jan 11 09:48:19 2019 +0100
@@ -143,7 +143,7 @@
 
         for name, value in extra.iteritems():
             if name.startswith(FILTER_PREFIX):
-                var = name[len(FILTER_PREFIX) :]
+                var = name[len(FILTER_PREFIX):]
                 extra_fields = form_args.setdefault(u"extra_fields", [])
                 extra_fields.append(data_form.Field(var=var, value=value))