logpai / Drain3

A robust streaming log template miner based on the Drain algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Masking Prefix and Suffix should not be escaped

bolu61 opened this issue · comments

The following escapes the prefix and suffix.

escaped_prefix = re.escape(self.masker.mask_prefix)
escaped_suffix = re.escape(self.masker.mask_suffix)

However, they are used in str.replace, which only does simple string replacement.

search_str = escaped_prefix + re.escape(mask_name) + escaped_suffix
while True:
rep_str = create_capture_regex(mask_name)
# Replace one-by-one to get a new param group name for each replacement.
template_regex_new = template_regex.replace(search_str, rep_str, 1)

Thus, if the prefix and suffix contained escaped characters, e.g. {{ and }} would become \\{\\{ and \\}\\}, the replacement would fail, and the constructed pattern will not match any parameteres.

I missed the line right after that also escapes the template...