def test_truncate_purified_field_xss():
 s = 'safe <script>alert("omg")</script>'
 t = PurifiedTranslation(localized_string=s)
 env = jingo.get_env()
 actual = env.from_string('{{ s|truncate(100) }}').render({'s': t})
 assert (actual == 'safe &lt;script&gt;alert("omg")&lt;/script&gt;')
 actual = env.from_string('{{ s|truncate(5) }}').render({'s': t})
 assert (actual == 'safe ...')

def test_truncate_purified_field_xss ( ) : s = 'safe <script>alert("omg")</script>' t = PurifiedTranslation ( localized_string = s ) env = jingo . get_env ( ) actual = env . from_string ( '{{ s|truncate(100) }}' ) . render ( { 's' : t } ) assert ( actual == 'safe &lt;script&gt;alert("omg")&lt;/script&gt;' ) actual = env . from_string ( '{{ s|truncate(5) }}' ) . render ( { 's' : t } ) assert ( actual == 'safe ...' )
truncating should not introduce xss issues .