Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
protect us from wayward localizers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Balogh committed Jul 29, 2011
1 parent 4f2677a commit bb4210e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
import logging
import os
import site
import sys
Expand Down Expand Up @@ -61,6 +62,22 @@
import session_csrf
session_csrf.monkeypatch()

# Fix jinja's Markup class to not crash when localizers give us bad format
# strings.
from jinja2 import Markup
mod = Markup.__mod__
trans_log = logging.getLogger('z.trans')


def new(self, arg):
try:
return mod(self, arg)
except Exception:
trans_log.error(unicode(self))
return ''

Markup.__mod__ = new

# Import for side-effect: configures our logging handlers.
# pylint: disable-msg=W0611
import log_settings
Expand Down

2 comments on commit bb4210e

@kumar303
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this fix but it seems like a dangerous monkey patch to keep around without a regression test. You can probably reproduce in a test case with render('one of the bad strings') no?

@jbalogh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You inspire me! jbalogh@6e6a287

Please sign in to comment.