Skip to content

Commit 63768cd

Browse files
committed
Fixed: newick to tree improper closing of ''
1 parent 8964292 commit 63768cd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

bigtree/tree/construct.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,10 +1182,14 @@ def _raise_value_error(tree_idx: int) -> None:
11821182
NewickState.PARSE_STRING,
11831183
NewickState.PARSE_ATTRIBUTE_NAME,
11841184
]:
1185+
if cumulative_string:
1186+
_raise_value_error(tree_string_idx)
11851187
cumulative_string = tree_string[
11861188
tree_string_idx + 1 : quote_end_idx # noqa: E203
11871189
]
11881190
else:
1191+
if cumulative_string_value:
1192+
_raise_value_error(tree_string_idx)
11891193
cumulative_string_value = tree_string[
11901194
tree_string_idx + 1 : quote_end_idx # noqa: E203
11911195
]

tests/tree/test_construct.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,6 +2554,24 @@ def test_newick_to_tree_node_type(self):
25542554
)
25552555
assert_tree_structure_node_root(root)
25562556

2557+
def test_newick_to_tree_invalid_character_error(self):
2558+
newick_strs_error = [
2559+
(
2560+
"""((d,(g,h)e)b,(f)c)"'a'\"""",
2561+
19,
2562+
), # NewickCharacter.ATTR_QUOTE, wrong order of bracket (name)
2563+
(
2564+
"""((d,(g,h)e)b,(f[age="'38'"])c)a""",
2565+
21,
2566+
), # NewickCharacter.ATTR_QUOTE, wrong order of bracket (attr value)
2567+
]
2568+
for newick_str, error_idx in newick_strs_error:
2569+
with pytest.raises(ValueError) as exc_info:
2570+
newick_to_tree(newick_str)
2571+
assert str(exc_info.value) == Constants.ERROR_NODE_NEWICK_NOT_CLOSED.format(
2572+
index=error_idx
2573+
)
2574+
25572575

25582576
def assert_tree_structure_phylogenetic(root):
25592577
assert root.max_depth == 4, f"Expected max_depth 4, received {root.max_depth}"

0 commit comments

Comments
 (0)