Skip to content

Commit

Permalink
Fix List index out of range in case of no match in a regex group
Browse files Browse the repository at this point in the history
Fixes #528
  • Loading branch information
bosd authored Oct 7, 2023
1 parent 6d8eec3 commit a274635
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/invoice2data/extract/parsers/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,22 @@ def parse(template, field, settings, content, legacy=False):

if "group" in settings:
result = list(filter(None, result))
if settings["group"] == "sum":
result = sum(result)
elif settings["group"] == "min":
result = min(result)
elif settings["group"] == "max":
result = max(result)
elif settings["group"] == "first":
result = result[0]
elif settings["group"] == "last":
result = result[-1]
elif settings["group"] == "join":
result = " ".join(str(v) for v in result)
else:
logger.warning("Unsupported grouping method: %s", settings["group"])
return None
if result:
if settings["group"] == "sum":
result = sum(result)
elif settings["group"] == "min":
result = min(result)
elif settings["group"] == "max":
result = max(result)
elif settings["group"] == "first":
result = result[0]
elif settings["group"] == "last":
result = result[-1]
elif settings["group"] == "join":
result = " ".join(str(v) for v in result)
else:
logger.warning("Unsupported grouping method: %s", settings["group"])
return None
else:

# Remove duplicates maintaining the order by default (it's more
Expand Down

0 comments on commit a274635

Please sign in to comment.