##// END OF EJS Templates
templater: do not reevaluate rawstring as template (BC)...
Yuya Nishihara -
r25597:fd5bc660 default
parent child Browse files
Show More
@@ -496,14 +496,14 b' def templatelabel(context, mapping, args'
496 496 # etc. don't need to be quoted
497 497 mapping.update(dict([(k, k) for k in _effects]))
498 498
499 thing = templater._evalifliteral(args[1], context, mapping)
499 thing = args[1][0](context, mapping, args[1][1])
500 500
501 501 # apparently, repo could be a string that is the favicon?
502 502 repo = mapping.get('repo', '')
503 503 if isinstance(repo, str):
504 504 return thing
505 505
506 label = templater._evalifliteral(args[0], context, mapping)
506 label = args[0][0](context, mapping, args[0][1])
507 507
508 508 thing = templater.stringify(thing)
509 509 label = templater.stringify(label)
@@ -146,8 +146,6 b' def getfilter(exp, context):'
146 146 def gettemplate(exp, context):
147 147 if exp[0] == 'template':
148 148 return compiletemplate(exp[1], context)
149 if exp[0] == 'rawstring':
150 return compiletemplate(exp[1], context, strtoken=exp[0])
151 149 if exp[0] == 'symbol':
152 150 return context._load(exp[1])
153 151 raise error.ParseError(_("expected template specifier"))
@@ -302,8 +300,8 b' def fill(context, mapping, args):'
302 300 # i18n: "fill" is a keyword
303 301 raise error.ParseError(_("fill expects an integer width"))
304 302 try:
305 initindent = stringify(_evalifliteral(args[2], context, mapping))
306 hangindent = stringify(_evalifliteral(args[3], context, mapping))
303 initindent = stringify(args[2][0](context, mapping, args[2][1]))
304 hangindent = stringify(args[3][0](context, mapping, args[3][1]))
307 305 except IndexError:
308 306 pass
309 307
@@ -318,7 +316,7 b' def pad(context, mapping, args):'
318 316
319 317 width = int(args[1][1])
320 318
321 text = stringify(_evalifliteral(args[0], context, mapping))
319 text = stringify(args[0][0](context, mapping, args[0][1]))
322 320
323 321 right = False
324 322 fillchar = ' '
@@ -368,15 +366,6 b' def get(context, mapping, args):'
368 366 key = args[1][0](context, mapping, args[1][1])
369 367 yield dictarg.get(key)
370 368
371 def _evalifliteral(arg, context, mapping):
372 # get back to token tag to reinterpret string as template
373 strtoken = {runrawstring: 'rawstring'}.get(arg[0])
374 if strtoken:
375 yield runtemplate(context, mapping,
376 compiletemplate(arg[1], context, strtoken))
377 else:
378 yield stringify(arg[0](context, mapping, arg[1]))
379
380 369 def if_(context, mapping, args):
381 370 """:if(expr, then[, else]): Conditionally execute based on the result of
382 371 an expression."""
@@ -386,9 +375,9 b' def if_(context, mapping, args):'
386 375
387 376 test = stringify(args[0][0](context, mapping, args[0][1]))
388 377 if test:
389 yield _evalifliteral(args[1], context, mapping)
378 yield args[1][0](context, mapping, args[1][1])
390 379 elif len(args) == 3:
391 yield _evalifliteral(args[2], context, mapping)
380 yield args[2][0](context, mapping, args[2][1])
392 381
393 382 def ifcontains(context, mapping, args):
394 383 """:ifcontains(search, thing, then[, else]): Conditionally execute based
@@ -401,9 +390,9 b' def ifcontains(context, mapping, args):'
401 390 items = args[1][0](context, mapping, args[1][1])
402 391
403 392 if item in items:
404 yield _evalifliteral(args[2], context, mapping)
393 yield args[2][0](context, mapping, args[2][1])
405 394 elif len(args) == 4:
406 yield _evalifliteral(args[3], context, mapping)
395 yield args[3][0](context, mapping, args[3][1])
407 396
408 397 def ifeq(context, mapping, args):
409 398 """:ifeq(expr1, expr2, then[, else]): Conditionally execute based on
@@ -415,9 +404,9 b' def ifeq(context, mapping, args):'
415 404 test = stringify(args[0][0](context, mapping, args[0][1]))
416 405 match = stringify(args[1][0](context, mapping, args[1][1]))
417 406 if test == match:
418 yield _evalifliteral(args[2], context, mapping)
407 yield args[2][0](context, mapping, args[2][1])
419 408 elif len(args) == 4:
420 yield _evalifliteral(args[3], context, mapping)
409 yield args[3][0](context, mapping, args[3][1])
421 410
422 411 def join(context, mapping, args):
423 412 """:join(list, sep): Join items in a list with a delimiter."""
@@ -451,7 +440,7 b' def label(context, mapping, args):'
451 440 raise error.ParseError(_("label expects two arguments"))
452 441
453 442 # ignore args[0] (the label string) since this is supposed to be a a no-op
454 yield _evalifliteral(args[1], context, mapping)
443 yield args[1][0](context, mapping, args[1][1])
455 444
456 445 def revset(context, mapping, args):
457 446 """:revset(query[, formatargs...]): Execute a revision set query. See
@@ -567,7 +556,7 b' def sub(context, mapping, args):'
567 556
568 557 pat = stringify(args[0][0](context, mapping, args[0][1]))
569 558 rpl = stringify(args[1][0](context, mapping, args[1][1]))
570 src = stringify(_evalifliteral(args[2], context, mapping))
559 src = stringify(args[2][0](context, mapping, args[2][1]))
571 560 yield re.sub(pat, rpl, src)
572 561
573 562 def startswith(context, mapping, args):
@@ -2812,6 +2812,12 b' Test string literal:'
2812 2812 $ hg log -Ra -r0 -T '{r"rawstring: {rev}"}\n'
2813 2813 rawstring: {rev}
2814 2814
2815 because map operation requires template, raw string can't be used
2816
2817 $ hg log -Ra -r0 -T '{files % r"rawstring"}\n'
2818 hg: parse error: expected template specifier
2819 [255]
2820
2815 2821 Test string escaping:
2816 2822
2817 2823 $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
@@ -2865,23 +2871,23 b' stripped before parsing:'
2865 2871 Test leading backslashes:
2866 2872
2867 2873 $ cd latesttag
2868 $ hg log -r 2 -T '\{rev} {files % "\{file}"} {files % r"\{file}"}\n'
2869 {rev} {file} \head1
2870 $ hg log -r 2 -T '\\{rev} {files % "\\{file}"} {files % r"\\{file}"}\n'
2871 \2 \head1 \\head1
2872 $ hg log -r 2 -T '\\\{rev} {files % "\\\{file}"} {files % r"\\\{file}"}\n'
2873 \{rev} \{file} \\\head1
2874 $ hg log -r 2 -T '\{rev} {files % "\{file}"}\n'
2875 {rev} {file}
2876 $ hg log -r 2 -T '\\{rev} {files % "\\{file}"}\n'
2877 \2 \head1
2878 $ hg log -r 2 -T '\\\{rev} {files % "\\\{file}"}\n'
2879 \{rev} \{file}
2874 2880 $ cd ..
2875 2881
2876 2882 Test leading backslashes in "if" expression (issue4714):
2877 2883
2878 2884 $ cd latesttag
2879 2885 $ hg log -r 2 -T '{if("1", "\{rev}")} {if("1", r"\{rev}")}\n'
2880 {rev} \2
2886 {rev} \{rev}
2881 2887 $ hg log -r 2 -T '{if("1", "\\{rev}")} {if("1", r"\\{rev}")}\n'
2882 \2 \\2
2888 \2 \\{rev}
2883 2889 $ hg log -r 2 -T '{if("1", "\\\{rev}")} {if("1", r"\\\{rev}")}\n'
2884 \{rev} \\\2
2890 \{rev} \\\{rev}
2885 2891 $ cd ..
2886 2892
2887 2893 "string-escape"-ed "\x5c\x786e" becomes r"\x6e" (once) or r"n" (twice)
@@ -2951,8 +2957,6 b' Test leading backslashes in "if" express'
2951 2957 fourth
2952 2958 second
2953 2959 third
2954 $ hg log -R a -r 8 --template '{files % r"{file}\n"}\n'
2955 fourth\nsecond\nthird\n
2956 2960
2957 2961 Test string escaping in nested expression:
2958 2962
@@ -3064,7 +3068,7 b' Test template string in pad function'
3064 3068 {0} test
3065 3069
3066 3070 $ hg log -r 0 -T '{pad(r"\{rev}", 10)} {author|user}\n'
3067 \0 test
3071 \{rev} test
3068 3072
3069 3073 Test ifcontains function
3070 3074
General Comments 0
You need to be logged in to leave comments. Login now