mod_python icon indicating copy to clipboard operation
mod_python copied to clipboard

Publisher missing GET variables

Open graywh opened this issue 11 months ago • 3 comments

It looks like the publisher handler is failing to pass 3-letter (and possibly shorter) GET variables to the function. I'm running 3.5.0.1 that's packaged for Debian.

graywh avatar Feb 05 '25 22:02 graywh

@graywh are you saying that if you make the variable 4 leterd long they do get passed? Can you provide a slightly more detailed example?

grisha avatar Feb 05 '25 22:02 grisha

Initially noticed because day wasn't working, but year and month did. Also, uid wasn't working, but usid did. This is an app that I created nearly 20 years ago and recently updated the OS from Debian buster to bookworm.

graywh avatar Feb 05 '25 22:02 graywh

index.py

def view(req, year=None, month=None, day=None):
    today = datetime.datetime.today()
    if not year:
        year = today.year
    if not month:
        month = today.month
    if not day:
        day = today.day
    year = int(year)
    month = int(month)
    day = int(day)
    req.content_type = 'text/html'
    tmpl = psp.PSP(req, filename='_templates/view.tmpl')
    tmpl.run({'year':year,
      'month':month,
      'day':day})

_templates/view.tmpl

<%
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
%>
<html><head></head><body>
<form action="add" method="get"><%
for j in [1,2]:
    # indent
%>
<select name="month<%= str(j) %>"><%
    for i, m in enumerate(months):
        # indent
%>
    <option value="<%= str(i + 1) %>"<%
        if i + 1 == month:
            # indent
            %> selected<%
        # end if
    %>><%= m %></option><%
    # end for
%>
</select>
<select name="day<%= str(j) %>"><%
    for i in range(1,32):
        # indent
%>
    <option value="<%= str(i) %>"<%
        if i == day:
            # indent
            %> selected<%
        # end if
    %>><%= str(i) %></option><%
    # end for
%>
</select>
<input type=submit value="Submit">
</form>
</body></html>

graywh avatar Feb 06 '25 00:02 graywh

Running into a similar issue after upgrading from Ubuntu 22.04 LTS to 24.04 LTS. Been using mod_python on apache2 there for a looong time over many releases without an issue. After upgrading, it seems if key OR value part of the query string has 3 or less characters, it shows random stuff, but not the original value. Easiest way to reproduce for me was this code snippet:

test.py

def index(**kwargs):
    return kwargs

Then just play around with parameters /pathtoscript/?foo=bar vs /pathtoscript/?fooo=baar

mgehrlein avatar Dec 29 '25 23:12 mgehrlein

I have a theory on what is happening here. I have a fix on this branch: https://github.com/grisha/mod_python/tree/144_query_params_bug - if anyone could verify that this fixes it in their set up, that'd be fantastic.

grisha avatar Dec 30 '25 01:12 grisha

Works for me with the test script provided above as well as with the old script that failed after upgrading. Thanks a lot!

mgehrlein avatar Dec 30 '25 11:12 mgehrlein

Great! I tagged version 3.5.0.6.

grisha avatar Dec 30 '25 16:12 grisha