Potential bug in forms

Adon Shapiro <[email protected]>
Newsgroups gmane.comp.web.lynx.devel
Message-ID <20211110212117.hjpc5oe2g7rwy6g5@latitude>
Hello,

I think I may have found a bug in the way Lynx submits forms. While testing a
personal website for text-only compatibility I came across an issue where a
form that I use to send an empty POST request is actually sending a GET request
but only in Lynx. I discovered that this happens consistently with any form
containing only a single input element. Adding a second input of any kind
results in the form being submitted correctly in Lynx.

To help recreate this, I have attached a small web server written in python3
demonstrating the requests sent from two example forms.

Additionally, here is the output of `lynx -version` in case that is useful:
Lynx Version 2.9.0dev.10 (11 Aug 2021)
libwww-FM 2.14, SSL-MM 1.4.1, GNUTLS 3.7.2, ncurses 6.2.20210905(wide)
Built on linux-gnu.

Best,
Adon
server.py (text/x-python, 1.3 KB)
from http.server import BaseHTTPRequestHandler, HTTPServer

html = """
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Lynx Form Test</title>
</head>
<body>
  <form method="post" action="/submit">
    <input type="submit" value="Misbehaves in Lynx">
  </form>
  <form method="post" action="/submit">
    <input type="hidden">
    <input type="submit" value="Behaves as expected">
  </form>
</body>
</html>
"""

class Handler(BaseHTTPRequestHandler):
    def __init__(self, request, client_address, server):
        self.msg = "Expected POST request. Actual method was {}."
        super().__init__(request, client_address, server)
    def respond(self, status, content_type, content):
        self.send_response(status)
        self.send_header("Content-Type", content_type)
        self.end_headers()
        self.wfile.write(bytes(content, "utf-8"))
    def do_GET(self):
        if self.path == "/submit":
            self.respond(200, "text/plain", self.msg.format("GET"))
            return
        self.respond(200, "text/html", html)
    def do_POST(self):
        if self.path == "/submit":
            self.respond(200, "text/plain", self.msg.format("POST"))
            return
        self.respond(405, "text/plain", "Method Not Allowed\n")

srv = HTTPServer(("", 8000), Handler)
print("Serving HTTP on port 8000 ...")
srv.serve_forever()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.