Skip to content

Commit 2e6a7ae

Browse files
authored
Merge pull request #755 from onekey-sec/753-overlap-fix
fix(models): adapt chunk's contains() definition.
2 parents c3e1ac5 + c8f24fd commit 2e6a7ae

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

tests/test_models.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,47 @@ class TestChunk:
1818
@pytest.mark.parametrize(
1919
"chunk1, chunk2, result",
2020
[
21-
(
21+
pytest.param(
2222
Chunk(start_offset=0, end_offset=10),
2323
Chunk(start_offset=1, end_offset=2),
2424
True,
25+
id="starts-after-ends-before",
2526
),
26-
(
27+
pytest.param(
2728
Chunk(start_offset=0, end_offset=10),
2829
Chunk(start_offset=11, end_offset=12),
2930
False,
31+
id="starts-after-ends-after",
3032
),
31-
(
33+
pytest.param(
3234
Chunk(start_offset=0, end_offset=10),
3335
Chunk(start_offset=15, end_offset=20),
3436
False,
37+
id="starts-after-ends-after",
3538
),
36-
(
39+
pytest.param(
3740
Chunk(start_offset=1, end_offset=2),
3841
Chunk(start_offset=3, end_offset=5),
3942
False,
43+
id="starts-after-ends-after",
4044
),
41-
(
45+
pytest.param(
4246
Chunk(start_offset=0, end_offset=10),
4347
Chunk(start_offset=1, end_offset=10),
4448
True,
49+
id="starts-after-ends-same",
50+
),
51+
pytest.param(
52+
Chunk(start_offset=0, end_offset=10),
53+
Chunk(start_offset=0, end_offset=9),
54+
True,
55+
id="starts-same-ends-before",
56+
),
57+
pytest.param(
58+
Chunk(start_offset=0, end_offset=10),
59+
Chunk(start_offset=0, end_offset=10),
60+
False,
61+
id="starts-same-ends-same",
4562
),
4663
],
4764
)

unblob/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def contains(self, other: "Chunk") -> bool:
8787
return (
8888
self.start_offset < other.start_offset
8989
and self.end_offset >= other.end_offset
90+
) or (
91+
self.start_offset <= other.start_offset
92+
and self.end_offset > other.end_offset
9093
)
9194

9295
def contains_offset(self, offset: int) -> bool:

0 commit comments

Comments
 (0)