Skip to content

Commit a31231e

Browse files
authored
fix: Fix to handle blank CONT lines (#8)
1 parent b86755c commit a31231e

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

gedcom7/parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ def loads(string: str) -> list[GedcomStructure]:
1414
for match in re.finditer(grammar.line, string):
1515
data = match.groupdict()
1616
level = int(data["level"])
17+
linestr = data["linestr"] or ""
1718
# handle continuation lines
1819
if data["tag"] == const.CONT:
19-
context[level - 1].text += "\n" + data["linestr"]
20+
context[level - 1].text += "\n" + linestr
2021
continue
2122
structure = GedcomStructure(
2223
tag=ext.get(data["tag"]) or data["tag"],
2324
pointer=data["pointer"],
2425
xref=data["xref"],
25-
text=data["linestr"],
26+
text=linestr,
2627
)
2728
# handle extension tags
2829
if (

test/test_parser.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,46 @@ def test_maximal():
4141
def test_exttag():
4242
records = gedcom7.loads(GEDCOM_EXTTAG)
4343
assert len(records) == 3
44-
assert records[1].children[1].tag == "http://example.com/placeholder"
44+
assert records[1].children[1].tag == "http://example.com/placeholder"
45+
46+
47+
GEDCOM_BLANK_CONT = """0 HEAD
48+
1 GEDC
49+
2 VERS 7.0
50+
0 @I1@ INDI
51+
1 NOTE This is a note
52+
2 CONT
53+
2 CONT with a blank line above
54+
0 TRLR
55+
"""
56+
57+
58+
def test_blank_cont_line():
59+
"""Test that blank CONT lines are handled correctly."""
60+
records = gedcom7.loads(GEDCOM_BLANK_CONT)
61+
assert len(records) == 3
62+
indi = records[1]
63+
note = indi.children[0]
64+
assert note.tag == "NOTE"
65+
assert note.text == "This is a note\n\nwith a blank line above"
66+
67+
68+
GEDCOM_EMPTY_VALUE = """0 HEAD
69+
1 GEDC
70+
2 VERS 7.0
71+
0 @O1@ OBJE
72+
1 FILE
73+
2 FORM image/jpeg
74+
0 TRLR
75+
"""
76+
77+
78+
def test_empty_line_value():
79+
"""Test that lines with no value (like empty FILE) are handled correctly."""
80+
records = gedcom7.loads(GEDCOM_EMPTY_VALUE)
81+
assert len(records) == 3
82+
obje = records[1]
83+
file_struct = obje.children[0]
84+
assert file_struct.tag == "FILE"
85+
assert file_struct.text == ""
86+
assert file_struct.children[0].tag == "FORM"

0 commit comments

Comments
 (0)