Ticket #5971: tokenparser_filter_fix.diff

File tokenparser_filter_fix.diff, 2.4 KB (added by Dmitri Fedortchenko <zeraien@…>, 17 years ago)

The patch

  • django/template/__init__.py

     
    458458        "A microparser that parses for a value: some string constant or variable name."
    459459        subject = self.subject
    460460        i = self.pointer
     461       
     462        def __next_space_index(subject, i):
     463            """Increment pointer until a real space (i.e. a space not within quotes) is encountered"""
     464            while i < len(subject) and subject[i] not in (' ', '\t'):
     465                if subject[i] in ('"', "'"):
     466                    c = subject[i]
     467                    i += 1
     468                    while i < len(subject) and subject[i] != c:
     469                        i += 1
     470                    if i >= len(subject):
     471                        raise TemplateSyntaxError, "Searching for value. Unexpected end of string in column %d: %s" % (i, subject)
     472                i += 1
     473            return i
     474       
    461475        if i >= len(subject):
    462476            raise TemplateSyntaxError, "Searching for value. Expected another value but found end of string: %s" % subject
    463477        if subject[i] in ('"', "'"):
     
    468482            if i >= len(subject):
    469483                raise TemplateSyntaxError, "Searching for value. Unexpected end of string in column %d: %s" % (i, subject)
    470484            i += 1
     485           
     486            # Continue parsing until next "real" space, so that filters are also included
     487            i = __next_space_index(subject, i)
     488           
    471489            res = subject[p:i]
    472490            while i < len(subject) and subject[i] in (' ', '\t'):
    473491                i += 1
     
    476494            return res
    477495        else:
    478496            p = i
    479             while i < len(subject) and subject[i] not in (' ', '\t'):
    480                 if subject[i] in ('"', "'"):
    481                     c = subject[i]
    482                     i += 1
    483                     while i < len(subject) and subject[i] != c:
    484                         i += 1
    485                     if i >= len(subject):
    486                         raise TemplateSyntaxError, "Searching for value. Unexpected end of string in column %d: %s" % (i, subject)
    487                 i += 1
     497            i = __next_space_index(subject, i)
    488498            s = subject[p:i]
    489499            while i < len(subject) and subject[i] in (' ', '\t'):
    490500                i += 1
Back to Top