cmds.projects.lib.templates: Fix string handling #98

Merged
Jan Lindemann merged 2 commits from jan/fix/20260913-cmds-projects-lib-templates-don-t-replace-escaped-markers into master 2026-09-13 21:25:13 +02:00 AGit

This PR fixes two independent defects in the projects template library, where merge_values() split string values into lists of characters and format_list_dict() substituted markers preceded by $ or { that were meant to survive verbatim:

cmds.projects.lib.templates: merge_values(): Don't split strings

is_list_dict() accepts a string value as a list-dict value, and render_values_to_list_dict() passes such values through unchanged. merge_values() then merges them with list extension, and [] += 'xyz' appends the individual characters, so every string value ends up as a list of its characters. Normalize string values to single-element lists in render_values_to_list_dict(), so that merge_values() appends whole values.

jw-pkg projects create-pkg-config is hit by this, because all of its values are strings: the generated file contains one line per character. The code path was just never exercised lately.

Add unit tests for the value layout guards, the normalization, and the merging of the three supported layouts.

cmds.projects.lib.templates: Don't replace escaped markers

format_list_dict() substitutes {key} markers with str.replace(), which also matches the marker inside ${key} and {{key}}, mangling text meant to survive verbatim, e.g. the ${prefix} variable reference of a pkg-config file. The built-in pkg-config template works around that with doubled braces, which produces {/usr}-style output instead.

Replace the markers with a regular expression that skips markers preceded by '$' or '{', and let the pkg-config template use the ${prefix} and ${exec_prefix} references pkg-config expects.

Extend the unit tests with marker escaping, value escaping, quoting, indentation, and the rendering of the built-in templates.

This PR fixes two independent defects in the projects template library, where merge_values() split string values into lists of characters and format_list_dict() substituted markers preceded by $ or { that were meant to survive verbatim: #### cmds.projects.lib.templates: merge_values(): Don't split strings is_list_dict() accepts a string value as a list-dict value, and render_values_to_list_dict() passes such values through unchanged. merge_values() then merges them with list extension, and [] += 'xyz' appends the individual characters, so every string value ends up as a list of its characters. Normalize string values to single-element lists in render_values_to_list_dict(), so that merge_values() appends whole values. jw-pkg projects create-pkg-config is hit by this, because all of its values are strings: the generated file contains one line per character. The code path was just never exercised lately. Add unit tests for the value layout guards, the normalization, and the merging of the three supported layouts. #### cmds.projects.lib.templates: Don't replace escaped markers format_list_dict() substitutes {key} markers with str.replace(), which also matches the marker inside ${key} and {{key}}, mangling text meant to survive verbatim, e.g. the ${prefix} variable reference of a pkg-config file. The built-in pkg-config template works around that with doubled braces, which produces {/usr}-style output instead. Replace the markers with a regular expression that skips markers preceded by '$' or '{', and let the pkg-config template use the ${prefix} and ${exec_prefix} references pkg-config expects. Extend the unit tests with marker escaping, value escaping, quoting, indentation, and the rendering of the built-in templates.
is_list_dict() accepts a string value as a list-dict value, and
render_values_to_list_dict() passes such values through unchanged.
merge_values() then merges them with list extension, and [] += 'xyz'
appends the individual characters, so every string value ends up as a list
of its characters. Normalize string values to single-element lists in
render_values_to_list_dict(), so that merge_values() appends whole values.

jw-pkg projects create-pkg-config is hit by this, because all of its values
are strings: the generated file contains one line per character. The code
path was just never exercised lately.

Add unit tests for the value layout guards, the normalization, and the
merging of the three supported layouts.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
cmds.projects.lib.templates: Don't replace escaped markers
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m43s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m42s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m13s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m21s
CI / Packaging test (push) Successful in 0s
61280e4695
format_list_dict() substitutes {key} markers with str.replace(), which also
matches the marker inside ${key} and {{key}}, mangling text meant to
survive verbatim, e.g. the ${prefix} variable reference of a pkg-config
file. The built-in pkg-config template works around that with doubled
braces, which produces {/usr}-style output instead.

Replace the markers with a regular expression that skips markers preceded
by '$' or '{', and let the pkg-config template use the ${prefix} and
${exec_prefix} references pkg-config expects.

Extend the unit tests with marker escaping, value escaping, quoting,
indentation, and the rendering of the built-in templates.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann changed title from cmds.projects.lib.templates: Don't replace escaped markers to cmds.projects.lib.templates: Fix string handling 2026-09-13 21:09:52 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
janware/jw-pkg!98
No description provided.