Ticket #12072: patch-12072.diff
File patch-12072.diff, 5.5 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/templates/tests.py
1031 1031 'url08': (u'{% url метка_оператора v %}', {'v': 'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 1032 1032 'url09': (u'{% url метка_оператора_2 tag=v %}', {'v': 'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 1033 1033 'url10': ('{% url regressiontests.templates.views.client_action id=client.id,action="two words" %}', {'client': {'id': 1}}, '/url_tag/client/1/two%20words/'), 1034 'url11': ('{% url regressiontests.templates.views.client_action id=client.id,action="==" %}', {'client': {'id': 1}}, '/url_tag/client/1/==/'), 1035 'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action="," %}', {'client': {'id': 1}}, '/url_tag/client/1/,/'), 1036 'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action=arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'), 1034 1037 1035 1038 # Failures 1036 1039 'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError), 1037 1040 'url-fail02': ('{% url no_such_view %}', {}, urlresolvers.NoReverseMatch), 1038 1041 'url-fail03': ('{% url regressiontests.templates.views.client %}', {}, urlresolvers.NoReverseMatch), 1042 'url-fail04': ('{% url view id, %}', {}, template.TemplateSyntaxError), 1043 'url-fail05': ('{% url view id= %}', {}, template.TemplateSyntaxError), 1044 'url-fail06': ('{% url view a.id=id %}', {}, template.TemplateSyntaxError), 1045 'url-fail07': ('{% url view a.id!id %}', {}, template.TemplateSyntaxError), 1046 'url-fail08': ('{% url view id="unterminatedstring %}', {}, template.TemplateSyntaxError), 1047 'url-fail09': ('{% url view id=", %}', {}, template.TemplateSyntaxError), 1039 1048 1040 1049 # {% url ... as var %} 1041 1050 'url-asvar01': ('{% url regressiontests.templates.views.index as url %}', {}, ''), -
django/template/defaulttags.py
7 7 from django.template import Node, NodeList, Template, Context, Variable 8 8 from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END 9 9 from django.template import get_library, Library, InvalidTemplateLibrary 10 from django.template import filter_re 10 11 from django.template.smartif import IfParser, Literal 11 12 from django.conf import settings 12 13 from django.utils.encoding import smart_str, smart_unicode … … 1118 1119 asvar = bits.next() 1119 1120 break 1120 1121 else: 1121 for arg in bit.split(","): 1122 if '=' in arg: 1123 k, v = arg.split('=', 1) 1124 k = k.strip() 1125 kwargs[k] = parser.compile_filter(v) 1126 elif arg: 1127 args.append(parser.compile_filter(arg)) 1122 matches = filter_re.finditer(bit) 1123 upto = 0 1124 while True: 1125 match = filter_re.match(bit[upto:]) 1126 if not match: 1127 raise TemplateSyntaxError("Could not parse: %s" % \ 1128 bit[upto:]) 1129 start, end = match.start()+upto, match.end()+upto 1130 1131 if end != len(bit) and bit[end] == '=': 1132 if not match.group("var"): 1133 raise TemplateSyntaxError("Keyword argument must be a variable name: %s" % \ 1134 bit[start:end]) 1135 arg_name = match.group("var") 1136 if '.' in arg_name: 1137 raise TemplateSyntaxError("Keyword name must not contain '.': %s" % \ 1138 arg_name) 1139 var_parts, var_end = filter_re.finditer(bit[end+1:]), 0 1140 1141 for i, var_part in enumerate(var_parts): 1142 if var_part.start() != var_end: 1143 break 1144 if (i == 0) ^ (var_part.group("filter_name") is None): 1145 raise TemplateSyntaxError("Malformed filter expression: %s" % \ 1146 bits[end+1:]) 1147 var_end = var_part.end() 1148 1149 if var_end == 0: 1150 raise TemplateSyntaxError("Keyword argument lacks value: %s" % \ 1151 arg_name) 1152 kwargs[arg_name] = parser.compile_filter(bit[end+1:var_end+end+1]) 1153 end = var_end + end + 1 1154 else: 1155 args.append(parser.compile_filter(bit[start:end])) 1156 1157 if end == len(bit): 1158 break 1159 if bit[end] != ',': 1160 raise TemplateSyntaxError("Arguments must be separated by ',', not '%s'" % \ 1161 bit[end:]) 1162 upto = end + 1 1163 1128 1164 return URLNode(viewname, args, kwargs, asvar) 1129 1165 url = register.tag(url) 1130 1166