From e6f38337160df77f52d031dba1422a5fd23dbf50 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 16 Aug 2026 12:19:23 +0200 Subject: [PATCH] load_yaml: Fix include spec parsing of pipes _INCLUDE_PATH_RE allows the pipe character in the target-path part of a jw.include spec such as 'target.path|file.yaml'. The greedy match then consumes further pipes, so a file name that itself contains a pipe is misparsed: the target swallows part of the file name and the remainder becomes the (nonexistent) file to open. Dots are needed in the target part for nested paths, but a pipe can never be part of a target path. Drop the pipe from the character class so that the first pipe always separates the target path from the file name. Add a regression test with a pipe in the file name. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann --- src/python/jw/util/load_yaml.py | 2 +- test/unit/python/jw/util/load_yaml/test.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/python/jw/util/load_yaml.py b/src/python/jw/util/load_yaml.py index 45c2ce7..1141094 100644 --- a/src/python/jw/util/load_yaml.py +++ b/src/python/jw/util/load_yaml.py @@ -14,7 +14,7 @@ IncludeSpec: TypeAlias = tuple[bool, Path, tuple[str, ...]] Includes: TypeAlias = list[IncludeSpec] _LINK_NAME_RE = re.compile(r'^([a-zA-Z0-9_-]+)\|') -_INCLUDE_PATH_RE = re.compile(r'^([a-zA-Z0-9_.|-]+)\|') +_INCLUDE_PATH_RE = re.compile(r'^([a-zA-Z0-9_.-]+)\|') # -- Low-level helpers (call graph leaves) -------------------------------------- diff --git a/test/unit/python/jw/util/load_yaml/test.py b/test/unit/python/jw/util/load_yaml/test.py index 6222802..b99240f 100644 --- a/test/unit/python/jw/util/load_yaml/test.py +++ b/test/unit/python/jw/util/load_yaml/test.py @@ -972,6 +972,17 @@ class TestIncludeWithPath: data = load_yaml(pathlib.Path(base) / 'main.yaml') assert data['section']['opt'] == 'val' + def test_include_pipe_in_filename(self, temp_dir: Callable) -> None: + """The first pipe separates target and file, pipes stay in the file.""" + base = temp_dir( + [ + ('weird|name.yaml', 'pip: ed\n'), + ('main.yaml', 'jw.include: section|weird|name.yaml\n'), + ] + ) + data = load_yaml(pathlib.Path(base) / 'main.yaml') + assert data['section']['pip'] == 'ed' + def test_include_plain_and_path_mixed(self, temp_dir: Callable) -> None: """Mix plain and path-based includes in same document.""" base = temp_dir(