Skip to content

Commit

Permalink
Unpickle context only from phased blocks
Browse files Browse the repository at this point in the history
Before this commit `utils.second_pass_render` tried to unpickle stashed
context from all bits of content resulting from splitting of template by
`PHASED_SECRET_DELIMITER`. Only odd bits are results of `phased` block
rendering, so only those bits contain stashed context. Even bits can't
contain stashed context and since they are results of first pass
rendering they can be arbitrary long and even for content of sane length
searching for regular expression match done in `unpickle_context` can
take insanely long time.  

Fixed by unpickling context only from odd bits.

Fixes: codysoyland#9
  • Loading branch information
jkuczm committed Sep 14, 2013
1 parent 2ebd7a6 commit d4fb2bf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions phased/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ def second_pass_render(request, content):
for index, bit in enumerate(content.split(settings.PHASED_SECRET_DELIMITER)):
if index % 2:
tokens = Lexer(bit, None).tokenize()
context = RequestContext(request,
restore_csrf_token(request, unpickle_context(bit)))
else:
tokens.append(Token(TOKEN_TEXT, bit))
tokens = [Token(TOKEN_TEXT, bit)]
context = None

context = RequestContext(request,
restore_csrf_token(request, unpickle_context(bit)))
rendered = Parser(tokens).parse().render(context)

if settings.PHASED_SECRET_DELIMITER in rendered:
Expand Down

0 comments on commit d4fb2bf

Please sign in to comment.