Jul-06-2017, 06:53 AM
(Jul-06-2017, 02:48 AM)Skaperen Wrote: here is a snippet of what i ended up coding:The problem is that is not correct

I you want to challenge yourself to write this,no problem.
Can use tool i show here to test code,
all that's need for code under is
pip install Flask
.>>> from flask import Markup >>> s = '<html><body>hello world</body></html>' >>> s = s.replace('&','&') ... s = s.replace('"','"') ... s = s.replace('<','<') ... s = s.replace('>','>') ... for n in list(range(32))+[39,92]: ... s = s.replace(chr(n),'&#'+hex(n)[1:]+';') >>> s '<html><body>hello world</body></html>' >>> test = Markup(s) >>> test Markup('<html><body>hello world</body></html>') >>> test.unescape() '<html><body>hello world</body></html>'
test.unescape()
should be '<html><body>hello world</body></html>'
With Jinja2 is battle proved and tested,
company like Mozilla use it and of course all that use Flask.
>>> import jinja2 >>> s = '<html><body>hello world</body></html>' >>> test = jinja2.escape(s) >>> test Markup('<html><body>hello world</body></html>') >>> test.unescape() '<html><body>hello world</body></html>'