Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions sigma/conversion/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from abc import ABC, abstractmethod
from collections import ChainMap, defaultdict
from contextlib import contextmanager
from itertools import pairwise
from typing import Any, Callable, ClassVar, Iterator, Pattern, cast

from typing_extensions import Self
Expand Down Expand Up @@ -1717,15 +1718,11 @@ def escape_and_quote_field(self, field_name: str) -> str:
match_positions.update((match.start() for match in re_quote.finditer(field_name)))

if len(match_positions) > 0: # found matches, escape them
r = [0] + list(sorted(match_positions)) + [len(field_name)]
escaped_field_name = ""
for i in range(
len(r) - 1
): # TODO: from Python 3.10 this can be replaced with itertools.pairwise(), but for now we keep support for Python <3.10
if i == 0: # The first range is passed to the result without escaping
escaped_field_name += field_name[r[i] : r[i + 1]]
else: # Subsequent ranges are positions of matches and therefore are prepended with field_escape
escaped_field_name += self.field_escape + field_name[r[i] : r[i + 1]]
indices = [0, *sorted(match_positions), len(field_name)]
escaped_field_name = self.field_escape.join(
field_name[first_index:second_index]
for (first_index, second_index) in pairwise(indices)
)
else: # no matches, just pass original field name without escaping
escaped_field_name = field_name
else:
Expand Down
Loading