Ticket #19160: 19160-poc.diff

File 19160-poc.diff, 1.0 KB (added by claudep, 3 years ago)

Proof of concept

  • django/utils/functional.py

    diff --git a/django/utils/functional.py b/django/utils/functional.py
    index 085a8fc..ad64802 100644
    a b  
    11import copy
     2import inspect
    23import operator
    34from functools import wraps, update_wrapper
     5import re
    46import sys
    57
    68from django.utils import six
    def lazy(func, *resultclasses): 
    153155        __hash__ = object.__hash__
    154156
    155157        def __mod__(self, rhs):
     158            if len(inspect.getargspec(func)[0]) > len(self.__args) and isinstance(rhs, dict):
     159                # Complete missing argument by looking for '%(var)d' in rhs,
     160                # used mainly by ungettext_lazy
     161                m = re.search('%\(([^)]*)\)d', self.__args[0])
     162                key = m.groups()[0] if m else None
     163                if key and key in rhs:
     164                    self.__args = self.__args + (rhs[key],)
    156165            if self._delegate_bytes and not six.PY3:
    157166                return bytes(self) % rhs
    158167            elif self._delegate_text:
Back to Top