Skip to content

Commit 21a0e62

Browse files
committed
fix escape not in cgi for newer pythons
1 parent e90430b commit 21a0e62

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

example/sp-wsgi/sp.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
from __future__ import print_function
33

44
import argparse
5-
import cgi
5+
try:
6+
import html
7+
except:
8+
import cgi as html
69
import importlib
710
import logging
811
import os
@@ -48,6 +51,9 @@
4851
from saml2.saml import NAMEID_FORMAT_PERSISTENT
4952
from saml2.samlp import Extensions
5053

54+
def _html_escape(payload):
55+
return html.escape(payload, quote=True)
56+
5157
logger = logging.getLogger("")
5258
hdlr = logging.FileHandler("spx.log")
5359
base_formatter = logging.Formatter("%(asctime)s %(name)s:%(levelname)s %(message)s")
@@ -699,7 +705,7 @@ def main(environ, start_response, sp):
699705
body = dict_to_table(user.data)
700706
body.append(
701707
"<br><pre>{authn_stmt}</pre>".format(
702-
authn_stmt=cgi.escape(user.authn_statement)
708+
authn_stmt=_html_escape(user.authn_statement)
703709
)
704710
)
705711
body.append("<br><a href='/logout'>logout</a>")

0 commit comments

Comments
 (0)