OILS / builtin / func_misc_test.py View on Github | oilshell.org

27 lines, 11 significant
1#!/usr/bin/env python2
2from __future__ import print_function
3
4import cgi
5import unittest
6
7
8class FuncsTest(unittest.TestCase):
9
10 def testHtmlEscape(self):
11 s = '<script>"This" isn\'t right</script>'
12 print(cgi.escape(s))
13
14 # Hm I think you're supposed to escape ' too
15 print(cgi.escape(s, quote=True))
16
17 # Python 3 enhanced this to take a dict
18 # https://docs.python.org/3.3/library/stdtypes.html?highlight=maketrans#str.maketrans
19 # We should write our own
20
21 d = {'<': '&lt;'}
22 #t = string.maketrans(['a', 'b'], ['aa', 'bb'])
23 #print(t)
24
25
26if __name__ == '__main__':
27 unittest.main()