Skip to content

Commit bfd0641

Browse files
committed
🎨 Test empty CGI params as None in iemapp
1 parent 5bdbf4e commit bfd0641

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to this library are documented in this file.
1414
fix a false positive and fix a bug. No data quality impacts (#1167).
1515
- Refactor `util.get_autoplot_context` into `autoplot.get_autoplot_context`.
1616
- Require python 3.11+
17+
- Treat inbound empty CGI parameters as effective `None`.
1718
- Update TAF storage to include an `issue` and `expire` timestamp, which
1819
explicitly stores the time domain. This change modified the storage of
1920
the observation to not include these timestamp values.

src/pyiem/webutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def _handle_exp(errormsg, routine=False, code=500):
517517
form = {
518518
k: v
519519
for k, v in _debracket(form).items()
520-
if k in kwargs["schema"].model_fields
520+
if k in kwargs["schema"].model_fields and v != ""
521521
}
522522
# Retain a reference to the Schema instance as it may have
523523
# private / computed attributes that are needed

tests/test_webutil.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ def application(_environ, start_response):
6767
assert resp.status_code == 422
6868

6969

70+
def test_empty_string():
71+
"""Test that emptry strings are not passed through..."""
72+
73+
class MyModel(CGIModel):
74+
bogus: Annotated[float | None, Field("Float")] = None
75+
76+
@iemapp(schema=MyModel)
77+
def application(environ, start_response):
78+
"""Test."""
79+
assert environ["bogus"] is None
80+
start_response("200 OK", [("Content-type", "text/plain")])
81+
return environ.get("unused", "OK")
82+
83+
c = Client(application)
84+
resp = c.get("/?bogus=")
85+
assert resp.status_code == 200
86+
assert resp.text == "OK"
87+
88+
7089
def test_gh1174_self():
7190
"""Test what happens with CGI self= is processed."""
7291

0 commit comments

Comments
 (0)