webapp.py: really fix schedule response
authorHelmut Grohne <helmut@subdivi.de>
Thu, 8 Oct 2020 19:54:15 +0000 (21:54 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Thu, 8 Oct 2020 19:54:15 +0000 (21:54 +0200)
Also handle invalid form values with a BadRequest.

Fixes: bab219106d1b ("webapp.py: fix schedule response")
Fixes: a52d12012b1b ("webapp: add concept of "build architecture" to frontend")

webapp.py

index 03d37b3..8cdd43a 100644 (file)
--- a/webapp.py
+++ b/webapp.py
@@ -278,8 +278,8 @@ schedule_template = """<!DOCTYPE html>
 <html>
  <body>
   <p>Scheduled a build of {{ request.form["source"]|e }}
-   {%- if request.form["archpair"] != "any_any" %}
-    for {{ request.form["archpair"]|archpair_format -}}
+   {%- if buildarch or hostarch %}
+    for {{ (buildarch|default("any"), hostarch|default("any"))|archpair_format -}}
    {%- endif %}.
   <p>
  </body>
@@ -422,7 +422,10 @@ def show_log(filename):
 @app.route("/schedule", methods=["POST"])
 def request_schedule():
     source = flask.request.form["source"]
-    buildarch, hostarch = flask.request.form["archpair"].split("_")
+    try:
+        buildarch, hostarch = flask.request.form["archpair"].split("_")
+    except ValueError:
+        raise werkzeug.exceptions.BadRequest()
     if buildarch == "any":
         buildarch = None
     elif buildarch != "amd64":
@@ -445,4 +448,5 @@ def request_schedule():
                 VALUES (:source, :buildarch, :hostarch, datetime('now'));""")
         conn.execute(query, source=source, buildarch=buildarch,
                      hostarch=hostarch)
-    return flask.render_template_string(schedule_template)
+    return flask.render_template_string(schedule_template, buildarch=buildarch,
+                                        hostarch=hostarch)