better cleaning

This commit is contained in:
James Tomasino 2023-02-24 14:07:44 +00:00
parent 13fbb70ef2
commit 8aa2e5761a
1 changed files with 4 additions and 4 deletions

View File

@ -11,9 +11,9 @@ urllib.parse.uses_relative.append("gemini")
urllib.parse.uses_netloc.append("gemini")
def clean(text):
return text.replace('&', '&amp;').replace('<','&lt;').replace('>','&gt;')
return text.replace('&', '&amp;').replace('<','&lt;').replace('>','&gt;').replace('"', '&quot;').replace('\'', '&#x27;')
print("Content-type: text/html\n\n")
print("Content-type: text/html\r\n\r\n")
if getenv('QUERY_STRING'):
try:
@ -29,7 +29,7 @@ if getenv('QUERY_STRING'):
preform = False
listmode = False
blockquote = False
for line in parser.parseText(responsetext.decode()):
for line in parser.parseText(responsetext.decode('utf8', errors='ignore')):
if line.linetype == gemtextparser.LineType.PREFORM:
if not preform:
print("<pre><code>")
@ -90,7 +90,7 @@ if getenv('QUERY_STRING'):
else:
print("<pre><code>")
print(clean(responsetext.decode()))
print(clean(responsetext.decode('utf8', errors='ignore')))
print("</code></pre>")
elif response.responsecode == 20: