mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Merge pull request #1103 from jasonccox/main
Require matching BEGIN and END lines in vobjects
This commit is contained in:
commit
762d369560
4 changed files with 38 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ In alphabetical order:
|
|||
- Corey Hinshaw
|
||||
- Kai Herlemann
|
||||
- Hugo Osvaldo Barrera
|
||||
- Jason Cox
|
||||
- Julian Mehne
|
||||
- Malte Kiefer
|
||||
- Marek Marczykowski-Górecki
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ Version 0.19.3
|
|||
- Added a no_delete option to the storage configuration. :gh:`1090`
|
||||
- Fix crash when running ``vdirsyncer repair`` on a collection. :gh:`1019`
|
||||
- Add an option to request vCard v4.0. :gh:`1066`
|
||||
- Require matching ``BEGIN`` and ``END`` lines in vobjects. :gh:`1103`
|
||||
|
||||
Version 0.19.2
|
||||
==============
|
||||
|
|
|
|||
|
|
@ -237,6 +237,31 @@ def test_broken_item():
|
|||
assert item.parsed is None
|
||||
|
||||
|
||||
def test_mismatched_end():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
vobject._Component.parse(
|
||||
[
|
||||
"BEGIN:FOO",
|
||||
"END:BAR",
|
||||
]
|
||||
)
|
||||
|
||||
assert "Got END:BAR, expected END:FOO at line 2" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_missing_end():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
vobject._Component.parse(
|
||||
[
|
||||
"BEGIN:FOO",
|
||||
"BEGIN:BAR",
|
||||
"END:BAR",
|
||||
]
|
||||
)
|
||||
|
||||
assert "Missing END for component(s): FOO" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_multiple_items():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
vobject._Component.parse(
|
||||
|
|
|
|||
|
|
@ -281,6 +281,12 @@ class _Component:
|
|||
stack.append(cls(c_name, [], []))
|
||||
elif line.startswith("END:"):
|
||||
component = stack.pop()
|
||||
c_name = line[len("END:") :].strip().upper()
|
||||
if c_name != component.name:
|
||||
raise ValueError(
|
||||
f"Got END:{c_name}, expected END:{component.name}"
|
||||
+ f" at line {_i + 1}"
|
||||
)
|
||||
if stack:
|
||||
stack[-1].subcomponents.append(component)
|
||||
else:
|
||||
|
|
@ -291,6 +297,11 @@ class _Component:
|
|||
except IndexError:
|
||||
raise ValueError(f"Parsing error at line {_i + 1}")
|
||||
|
||||
if len(stack) > 0:
|
||||
raise ValueError(
|
||||
f"Missing END for component(s): {', '.join(c.name for c in stack)}"
|
||||
)
|
||||
|
||||
if multiple:
|
||||
return rv
|
||||
elif len(rv) != 1:
|
||||
|
|
|
|||
Loading…
Reference in a new issue