Skip to content

Commit

Permalink
SigmaString slice with start after end results in empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspatzke committed Oct 5, 2022
1 parent 0cee443 commit 3db4bc5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pySigma"
version = "0.8.6"
version = "0.8.7"
license = "LGPL-2.1-only"
description = "Sigma rule processing and conversion tools"
authors = ["Thomas Patzke <[email protected]>"]
Expand Down
4 changes: 2 additions & 2 deletions sigma/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def __getitem__(self, idx : Union[int, slice]) -> "SigmaString":
end = length + end

# Range checks
if start > end:
if start > end or start >= length:
return SigmaString("")
if start < 0 or end < 0 or start >= length or (end != inf and end > length):
if start < 0 or end < 0 or (end != inf and end > length):
raise IndexError("SigmaString index out of range")

i = 0 # Pointer to SigmaString element
Expand Down
3 changes: 1 addition & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ def test_string_index_slice_empty_result(sigma_string):
assert sigma_string[4:2] == SigmaString("")

def test_string_index_slice_start_after_end(sigma_string):
with pytest.raises(IndexError, match="out of range"):
assert sigma_string[100:]
assert sigma_string[100:] == SigmaString("")

def test_string_index_slice_open_start_negative_end(sigma_string):
assert sigma_string[:-1] == SigmaString("*Test*Str\\*ing")
Expand Down

0 comments on commit 3db4bc5

Please sign in to comment.