From a0f9dd8b8f9058588a8ddc781922b0bd97518820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannik=20R=C3=B6del?= Date: Sun, 14 Apr 2024 16:38:05 +0200 Subject: [PATCH] Apply default value for string form fields if they are empty --- cgi-bin/form.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cgi-bin/form.py b/cgi-bin/form.py index f047682..cb8ff53 100755 --- a/cgi-bin/form.py +++ b/cgi-bin/form.py @@ -172,6 +172,8 @@ def get_form_value( result = cast(form.getfirst(name)) if isinstance(result, str): result = result.strip() + if not result and default is not None: + return default return result except (TypeError, ValueError): fail("400 Bad Request", f"Invalid value for field: {name}")