Handle missing characters in inlinefunc as per #1498

This commit is contained in:
Griatch 2018-06-16 22:14:28 +02:00
parent 2eaae6ac48
commit d047f2b919

View file

@ -191,16 +191,15 @@ except AttributeError:
_RE_STARTTOKEN = re.compile(r"(?<!\\)\$(\w+)\(") # unescaped $funcname{ (start of function call) _RE_STARTTOKEN = re.compile(r"(?<!\\)\$(\w+)\(") # unescaped $funcname{ (start of function call)
_RE_TOKEN = re.compile(r""" _RE_TOKEN = re.compile(r"""
(?<!\\)\'\'\'(?P<singlequote>.*?)(?<!\\)\'\'\'| # unescaped single-triples (escapes all inside them) (?<!\\)\'\'\'(?P<singlequote>.*?)(?<!\\)\'\'\'| # unescaped single-triples (escapes all inside them)
(?<!\\)\"\"\"(?P<doublequote>.*?)(?<!\\)\"\"\"| # unescaped normal triple quotes (escapes all inside them) (?<!\\)\"\"\"(?P<doublequote>.*?)(?<!\\)\"\"\"| # unescaped normal triple quotes (escapes all inside them)
(?P<comma>(?<!\\)\,)| # unescaped , (argument separator) (?P<comma>(?<!\\)\,)| # unescaped , (argument separator)
(?P<end>(?<!\\)\))| # unescaped ) (end of function call) (?P<end>(?<!\\)\))| # unescaped ) (end of function call)
(?P<start>(?<!\\)\$\w+\()| # unescaped $funcname( (start of function call) (?P<start>(?<!\\)\$\w+\()| # unescaped $funcname( (start of function call)
(?P<escaped>\\'|\\"|\\\)|\\$\w+\()| # escaped tokens should re-appear in text (?P<escaped>\\'|\\"|\\\)|\\$\w+\()| # escaped tokens should re-appear in text
(?P<rest>[\w\s.-\/#@$\>\<!%\^&\*;:=\-_`~\|\(}{\[\]]+|\"{1}|\'{1}) # everything else should also be included""", (?P<rest>[\w\s.-\/#!%\^&\*;:=\-_`~\|\(}{\[\]@\$\\\+\<\>?]+|\"{1}|\'{1}) # everything else """,
re.UNICODE + re.IGNORECASE + re.VERBOSE + re.DOTALL) re.UNICODE + re.IGNORECASE + re.VERBOSE + re.DOTALL)
# Cache for function lookups. # Cache for function lookups.
_PARSING_CACHE = utils.LimitedSizeOrderedDict(size_limit=1000) _PARSING_CACHE = utils.LimitedSizeOrderedDict(size_limit=1000)
@ -370,6 +369,7 @@ def parse_inlinefunc(string, strip=False, available_funcs=None, **kwargs):
retval = "" if strip else func(*args, **kwargs) retval = "" if strip else func(*args, **kwargs)
return utils.to_str(retval, force_string=True) return utils.to_str(retval, force_string=True)
print("STACK:\n{}".format(stack))
# execute the stack # execute the stack
return "".join(_run_stack(item) for item in stack) return "".join(_run_stack(item) for item in stack)
@ -405,6 +405,7 @@ Custom arg markers
$N argument position (1-99) $N argument position (1-99)
""" """
import fnmatch import fnmatch
_RE_NICK_ARG = re.compile(r"\\(\$)([1-9][0-9]?)") _RE_NICK_ARG = re.compile(r"\\(\$)([1-9][0-9]?)")
_RE_NICK_TEMPLATE_ARG = re.compile(r"(\$)([1-9][0-9]?)") _RE_NICK_TEMPLATE_ARG = re.compile(r"(\$)([1-9][0-9]?)")
@ -446,7 +447,6 @@ def initialize_nick_templates(in_template, out_template):
# validate the tempaltes - they should at least have the same number of args # validate the tempaltes - they should at least have the same number of args
n_outargs = len(_RE_NICK_TEMPLATE_ARG.findall(out_template)) n_outargs = len(_RE_NICK_TEMPLATE_ARG.findall(out_template))
if n_inargs != n_outargs: if n_inargs != n_outargs:
print n_inargs, n_outargs
raise NickTemplateInvalid raise NickTemplateInvalid
return re.compile(regex_string), template_string return re.compile(regex_string), template_string