load_yaml: Fix dropped inplace-link siblings
A jw.inplace-link node deep-merges its sibling keys into the resolved target. When the target resolves to a non-dict value, the merge is skipped and the sibling keys are silently discarded, losing document data without any warning. Raise ValueError when the resolved target is not a mapping and the node carries sibling keys, and add regression tests for scalar and list targets. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
2bd1db5d90
commit
b3a3fc0507
1 changed files with 29 additions and 4 deletions
|
|
@ -669,10 +669,30 @@ class TestInplaceLink:
|
|||
assert data['entry']['flag'] is True
|
||||
|
||||
def test_inplace_link_non_dict_target(self, yaml_file: Callable) -> None:
|
||||
"""Non-dict target replaces entirely; siblings dropped."""
|
||||
"""Non-dict target without siblings replaces the value."""
|
||||
data = load_yaml(yaml_file('target: val\nentry:\n jw.inplace-link: target\n'))
|
||||
assert data['entry'] == 'val'
|
||||
|
||||
def test_inplace_link_non_dict_target_siblings_raise(
|
||||
self, yaml_file: Callable
|
||||
) -> None:
|
||||
"""Non-dict target with sibling keys raises instead of dropping them."""
|
||||
with pytest.raises(ValueError, match = 'not a mapping'):
|
||||
load_yaml(
|
||||
yaml_file(
|
||||
'target: val\nentry:\n jw.inplace-link: target\n extra: kept\n'
|
||||
)
|
||||
)
|
||||
|
||||
def test_inplace_link_list_target_siblings_raise(self, yaml_file: Callable) -> None:
|
||||
"""List target with sibling keys raises instead of dropping them."""
|
||||
with pytest.raises(ValueError, match = 'not a mapping'):
|
||||
load_yaml(
|
||||
yaml_file(
|
||||
'target:\n - a\nentry:\n jw.inplace-link: target\n extra: kept\n'
|
||||
)
|
||||
)
|
||||
|
||||
def test_inplace_link_relative_path(self, yaml_file: Callable) -> None:
|
||||
"""jw.inplace-link supports relative paths."""
|
||||
data = load_yaml(
|
||||
|
|
|
|||
Loading…
Reference in a new issue