def test_truncate_purified_field_xss(): """Truncating should not introduce xss issues.""" s = 'safe <script>alert("omg")</script>' t = PurifiedTranslation(localized_string=s) actual = env.from_string('{{ s|truncate(100) }}').render({'s': t}) eq_(actual, 'safe <script>alert("omg")</script>') actual = env.from_string('{{ s|truncate(5) }}').render({'s': t}) eq_(actual, 'safe ...')
def rendered_content(self): from mkt.site.utils import env # django import order LOL :-( template = self.template_name context_instance = self.resolve_context(self.context_data) request = context_instance['request'] # Gross, let's figure out if we're in the admin. if self._current_app == 'admin': source = loader.render_to_string(template, context_instance) template = env.from_string(source) # This interferes with our media() helper. if 'media' in self.context_data: del self.context_data['media'] # ``render_to_string`` only accepts a Template instance or a template name, # not a list. if isinstance(template, (list, tuple)): template = loader.select_template(template) return jingo.render_to_string(request, template, self.context_data)
def rendered_content(self): from mkt.site.utils import env # django import order LOL :-( template = self.template_name if 'user' not in self.context_data: self.context_data['user'] = self._request.user context_instance = self.resolve_context(self.context_data) # Gross, let's figure out if we're in the admin. if getattr(self._request, 'current_app', None) == 'admin': source = loader.render_to_string( template, RequestContext(self._request, context_instance)) template = env.from_string(source) # This interferes with our media() helper. if 'media' in self.context_data: del self.context_data['media'] # ``render_to_string`` only accepts a Template instance or a template name, # not a list. if isinstance(template, (list, tuple)): template = loader.select_template(template) if isinstance(template, Template): template = template.template return jingo.render_to_string(self._request, template, self.context_data)
def test_truncate_purified_field(): s = '<i>one</i><i>two</i>' t = PurifiedTranslation(localized_string=s) actual = env.from_string('{{ s|truncate(6) }}').render({'s': t}) eq_(actual, s)
def render(s, context={}): return env.from_string(s).render(context)
def render(self, s, context={}): t = env.from_string(s) return t.render(context)