##// END OF EJS Templates
templater: abort if infinite recursion detected while evaluation (issue4758)...
Yuya Nishihara -
r27939:7ed3a3c0 stable
parent child Browse files
Show More
@@ -226,13 +226,22 b' def runinteger(context, mapping, data):'
226 def runstring(context, mapping, data):
226 def runstring(context, mapping, data):
227 return data
227 return data
228
228
229 def _recursivesymbolblocker(key):
230 def showrecursion(**args):
231 raise error.Abort(_("recursive reference '%s' in template") % key)
232 return showrecursion
233
229 def runsymbol(context, mapping, key):
234 def runsymbol(context, mapping, key):
230 v = mapping.get(key)
235 v = mapping.get(key)
231 if v is None:
236 if v is None:
232 v = context._defaults.get(key)
237 v = context._defaults.get(key)
233 if v is None:
238 if v is None:
239 # put poison to cut recursion. we can't move this to parsing phase
240 # because "x = {x}" is allowed if "x" is a keyword. (issue4758)
241 safemapping = mapping.copy()
242 safemapping[key] = _recursivesymbolblocker(key)
234 try:
243 try:
235 v = context.process(key, mapping)
244 v = context.process(key, safemapping)
236 except TemplateNotFound:
245 except TemplateNotFound:
237 v = ''
246 v = ''
238 if callable(v):
247 if callable(v):
@@ -1035,6 +1035,33 b' Include works:'
1035 1
1035 1
1036 0
1036 0
1037
1037
1038 Check that recursive reference does not fall into RuntimeError (issue4758):
1039
1040 common mistake:
1041
1042 $ hg log -T '{changeset}\n'
1043 abort: recursive reference 'changeset' in template
1044 [255]
1045
1046 circular reference:
1047
1048 $ cat << EOF > issue4758
1049 > changeset = '{foo}'
1050 > foo = '{changeset}'
1051 > EOF
1052 $ hg log --style ./issue4758
1053 abort: recursive reference 'foo' in template
1054 [255]
1055
1056 not a recursion if a keyword of the same name exists:
1057
1058 $ cat << EOF > issue4758
1059 > changeset = '{tags % rev}'
1060 > rev = '{rev} {tag}\n'
1061 > EOF
1062 $ hg log --style ./issue4758 -r tip
1063 8 tip
1064
1038 Check that {phase} works correctly on parents:
1065 Check that {phase} works correctly on parents:
1039
1066
1040 $ cat << EOF > parentphase
1067 $ cat << EOF > parentphase
General Comments 0
You need to be logged in to leave comments. Login now