##// END OF EJS Templates
templater: catch regexp error at sub() function...
Yuya Nishihara -
r26188:662ea52d default
parent child Browse files
Show More
@@ -660,7 +660,16 b' def sub(context, mapping, args):'
660 pat = stringify(args[0][0](context, mapping, args[0][1]))
660 pat = stringify(args[0][0](context, mapping, args[0][1]))
661 rpl = stringify(args[1][0](context, mapping, args[1][1]))
661 rpl = stringify(args[1][0](context, mapping, args[1][1]))
662 src = stringify(args[2][0](context, mapping, args[2][1]))
662 src = stringify(args[2][0](context, mapping, args[2][1]))
663 yield re.sub(pat, rpl, src)
663 try:
664 patre = re.compile(pat)
665 except re.error:
666 # i18n: "sub" is a keyword
667 raise error.ParseError(_("sub got an invalid pattern: %s") % pat)
668 try:
669 yield patre.sub(rpl, src)
670 except re.error:
671 # i18n: "sub" is a keyword
672 raise error.ParseError(_("sub got an invalid replacement: %s") % rpl)
664
673
665 def startswith(context, mapping, args):
674 def startswith(context, mapping, args):
666 """:startswith(pattern, text): Returns the value from the "text" argument
675 """:startswith(pattern, text): Returns the value from the "text" argument
@@ -2731,6 +2731,13 b' Test the sub function of templating for '
2731 $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n'
2731 $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n'
2732 xx
2732 xx
2733
2733
2734 $ hg log -R latesttag -r 10 -T '{sub("[", "x", rev)}\n'
2735 hg: parse error: sub got an invalid pattern: [
2736 [255]
2737 $ hg log -R latesttag -r 10 -T '{sub("[0-9]", r"\1", rev)}\n'
2738 hg: parse error: sub got an invalid replacement: \1
2739 [255]
2740
2734 Test the strip function with chars specified:
2741 Test the strip function with chars specified:
2735
2742
2736 $ hg log -R latesttag --template '{desc}\n'
2743 $ hg log -R latesttag --template '{desc}\n'
General Comments 0
You need to be logged in to leave comments. Login now