Skip to content

Commit c79d368

Browse files
committed
Fix _Component.__delitem__ with adjacent identical keys
Hypothesis found the following example: ``` tests/unit/utils/test_vobject.py:335: in add_prop assert c[key] == value E AssertionError: assert '0' == '1' E E - 1 E + 0 E Falsifying example: E state = VobjectMachine() E unparsed_0 = state.get_unparsed_lines(encoded=False, joined=False) E parsed_0 = state.parse(unparsed=unparsed_0) E state.add_prop_raw(c=parsed_0, key='0', params=[], value='0') E state.add_prop_raw(c=parsed_0, key='0', params=[], value='0') E state.add_prop(c=parsed_0, key='0', value='1') E state.teardown() ``` After the two `add_prop_raw` calls, `c.props` is `["0;:0", "0;:0", "FOO:YES"]`. `_Component.__delitem__` then fails to effectively delete the previous key: it deletes the first `"0;:0"` item, but then checks for continuation lines following it and incorrectly keeps the second `"0;:0"` item even though it begins with one of the prefixes it's trying to delete. Checking for the prefix in the check for continuation lines fixes this. Fixes: #1149
1 parent cd050d5 commit c79d368

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

vdirsyncer/vobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def __delitem__(self, key):
329329
break
330330

331331
for line in lineiter:
332-
if not line.startswith((" ", "\t")):
332+
if not line.startswith((" ", "\t", *prefix)):
333333
new_lines.append(line)
334334
break
335335

0 commit comments

Comments
 (0)