You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2021/06/06 10:31:53 UTC

[incubator-ponymail-foal] branch master updated: Add some additional assertions about keyword syntax

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new c3490a4  Add some additional assertions about keyword syntax
c3490a4 is described below

commit c3490a405680e21e884c61a92d1f1a83cef7b083
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Jun 6 12:31:47 2021 +0200

    Add some additional assertions about keyword syntax
---
 server/plugins/defuzzer.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/server/plugins/defuzzer.py b/server/plugins/defuzzer.py
index a616ca3..bdd3133 100644
--- a/server/plugins/defuzzer.py
+++ b/server/plugins/defuzzer.py
@@ -38,8 +38,10 @@ def defuzz(formdata: dict, nodate: bool = False) -> dict:
         formdata["e"] = formdata["date"]
     # classic start and end month params
     if "s" in formdata and "e" in formdata:
-        syear, smonth = formdata["s"].split("-")
-        eyear, emonth = formdata["e"].split("-")
+        assert re.match(r"\d{4}-\d{1,2}$", formdata["s"]), "Keyword 's' must be of type YYYY-MM"
+        assert re.match(r"\d{4}-\d{1,2}$", formdata["e"]), "Keyword 'e' must be of type YYYY-MM"
+        syear, smonth = formdata["s"].split("-", 1)
+        eyear, emonth = formdata["e"].split("-", 1)
         _estart, eend = calendar.monthrange(int(eyear), int(emonth))
         daterange = {
             "gt": "%04u/%02u/01 00:00:00" % (int(syear), int(smonth)),
@@ -72,8 +74,8 @@ def defuzz(formdata: dict, nodate: bool = False) -> dict:
         if m:
             dfr = m.group(1)
             dto = m.group(2)
-            syear, smonth, sday = dfr.split("-")
-            eyear, emonth, eday = dto.split("-")
+            syear, smonth, sday = dfr.split("-", 1)
+            eyear, emonth, eday = dto.split("-", 1)
             daterange = {
                 "gt": "%04u/%02u/%02u 00:00:00" % (int(syear), int(smonth), int(sday)),
                 "lt": "%04u/%02u/%02u 23:59:59" % (int(eyear), int(emonth), int(eday)),