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:
Jan Lindemann 2026-08-16 12:18:55 +02:00
commit 1fd3c75c08
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -187,11 +187,16 @@ def _resolve_link(
) -> tuple[bool, str | None, tuple[str, ...], Any]:
"""Parse *spec* and resolve its target path against *root*.
Returns ``(is_named, name, target_path, target_value)``. A missing
or invalid target raises ``ValueError`` naming the link and its
location. Path navigation operates on the unexpanded tree, so
intermediate segments must not be link nodes themselves.
Returns ``(is_named, name, target_path, target_value)``. A
non-string spec raises ``TypeError``; a missing or invalid target
raises ``ValueError`` naming the link and its location. Path
navigation operates on the unexpanded tree, so intermediate
segments must not be link nodes themselves.
"""
if not isinstance(spec, str):
raise TypeError(
f'{kind} value must be a string, got {type(spec).__name__}: {spec!r}'
)
is_named, name, path = _parse_link(spec)
where = '.'.join(str(part) for part in current_path)
if not where: