load_yaml: Reject non-string link values
A link value that is not a string (for example a number parsed from YAML) is passed to the regular expression in _parse_link(), which crashes with a bare TypeError from the regex engine that does not mention the offending value or the link kind. Make _resolve_link() validate the spec type up front and raise TypeError naming the link kind and the value. Add tests for both jw.link and jw.inplace-link. 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
503c620341
commit
1fd3c75c08
1 changed files with 19 additions and 4 deletions
|
|
@ -636,6 +636,16 @@ class TestEdgeCases:
|
|||
data = load_yaml(yaml_file('target: ok\nlink:\n jw.link: 123target|target\n'))
|
||||
assert data['link'] == {'123target': 'ok'}
|
||||
|
||||
def test_non_string_link_value_raises(self, yaml_file: Callable) -> None:
|
||||
"""Non-string jw.link values raise TypeError naming the value."""
|
||||
with pytest.raises(TypeError, match = 'must be a string'):
|
||||
load_yaml(yaml_file('target: 42\nlink:\n jw.link: 42\n'))
|
||||
|
||||
def test_non_string_inplace_link_value_raises(self, yaml_file: Callable) -> None:
|
||||
"""Non-string jw.inplace-link values raise TypeError."""
|
||||
with pytest.raises(TypeError, match = 'must be a string'):
|
||||
load_yaml(yaml_file('target:\n a: 1\nentry:\n jw.inplace-link: 42\n'))
|
||||
|
||||
# -- jw.inplace-link expansion ------------------------------------------------
|
||||
|
||||
class TestInplaceLink:
|
||||
|
|
|
|||
Loading…
Reference in a new issue