Skip to content

Commit 86109ae

Browse files
caryosceluscanewsin
authored andcommitted
fix readdress loop
use better escaping in render fixes #19
1 parent 611fc77 commit 86109ae

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Ui/UiRequest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,25 @@ def xescape(s):
563563
repl.update(html_chars)
564564
return s.translate(repl)
565565

566+
def xescape(s):
567+
'''combines parts from re.escape & html.escape'''
568+
# https://github.com/python/cpython/blob/3.10/Lib/re.py#L267
569+
# '&' is handled otherwise
570+
re_chars = {i: '\\' + chr(i) for i in b'()[]{}*+-|^$\\.~# \t\n\r\v\f'}
571+
# https://github.com/python/cpython/blob/3.10/Lib/html/__init__.py#L12
572+
html_chars = {
573+
'<' : '&lt;',
574+
'>' : '&gt;',
575+
'"' : '&quot;',
576+
"'" : '&#x27;',
577+
}
578+
# we can't replace '&' because it makes certain zites work incorrectly
579+
# it should however in no way interfere with re.sub in render
580+
repl = {}
581+
repl.update(re_chars)
582+
repl.update(html_chars)
583+
return s.translate(repl)
584+
566585
return self.render(
567586
"src/Ui/template/wrapper.html",
568587
server_url=server_url,

0 commit comments

Comments
 (0)