[projects/pld-ftp-admin] web: serve and read forms in UTF-8

arekm arekm at pld-linux.org
Sat Oct 24 11:46:39 CEST 2026


commit 0898f517f01baa62d317ff81ba45943427156524
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Tue Oct 20 16:39:06 2026 +0200

    web: serve and read forms in UTF-8
    
    Passwords with Polish characters never matched.

 html/header.html    | 2 +-
 modules/wwwiface.py | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/html/header.html b/html/header.html
index 80a3694..b1491da 100644
--- a/html/header.html
+++ b/html/header.html
@@ -1,7 +1,7 @@
 <html>
 
 <head>
-<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
+<meta http-equiv="content-type" content="text/html; charset=utf-8" />
 <title>PLD ftp manager - Th</title>
 <style type="text/css" media="all">@import "../html/layout.css";</style>
 </head>
diff --git a/modules/wwwiface.py b/modules/wwwiface.py
index 43f7ff7..cfdc01f 100644
--- a/modules/wwwiface.py
+++ b/modules/wwwiface.py
@@ -4,7 +4,7 @@ from http.cookies import SimpleCookie
 from urllib.parse import parse_qsl
 
 # html/header.html declares it, so browsers also send form data in it
-CHARSET = 'iso-8859-1'
+CHARSET = 'utf-8'
 
 
 def getfile(file):
@@ -16,7 +16,8 @@ def getopts(environ):
     fields = parse_qsl(environ.get('QUERY_STRING', ''), encoding=CHARSET)
     if environ['REQUEST_METHOD'] == 'POST':
         length = int(environ.get('CONTENT_LENGTH') or 0)
-        fields += parse_qsl(environ['wsgi.input'].read(length).decode(CHARSET), encoding=CHARSET)
+        # the body is percent-encoded ASCII; latin-1 can't fail on stray bytes
+        fields += parse_qsl(environ['wsgi.input'].read(length).decode('latin-1'), encoding=CHARSET)
 
     cookies = {}
     for key, morsel in SimpleCookie(environ.get('HTTP_COOKIE', '')).items():
@@ -26,7 +27,7 @@ def getopts(environ):
 
 class Page:
     def __init__(self):
-        self.headers = [('Content-Type', 'text/html')]
+        self.headers = [('Content-Type', f'text/html; charset={CHARSET}')]
         self.header = []
         self.menu = []
         self.content = []
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/e14cb7d4d74f8bdd9368d9645ecaf49593cf6335



More information about the pld-cvs-commit mailing list