Skip to content

fix: use portable syntax to strip trailing comma in build_fields#70

Open
mc0de wants to merge 1 commit into
fieu:masterfrom
mc0de:fix/field-param-fix
Open

fix: use portable syntax to strip trailing comma in build_fields#70
mc0de wants to merge 1 commit into
fieu:masterfrom
mc0de:fix/field-param-fix

Conversation

@mc0de

@mc0de mc0de commented May 9, 2026

Copy link
Copy Markdown

This PR fixes two bugs that together made --field completely non-functional.

Bug 1: add_field always exited early

add_field guards against being called outside of an embed context:

[[ -z "${embedding}" ]] && exit;

However, in the argument parser, embedding=1 was set after calling add_field:

--field*) add_field "${2}"; embedding=1; shift; shift;;

This meant that when --field was the first (or only) embed-related flag, embedding was still unset when add_field ran, causing it to exit immediately without appending anything to fields.

Fix: swapped the order so embedding=1 is set before add_field is called.


Bug 2: ${fields::-1} silently fails on bash < 4.2

build_fields used ${fields::-1} to strip the trailing comma from the accumulated field entries. This negative-length substring expansion requires bash 4.2+ and silently produces no output on macOS, which ships with bash 3.2 by default.

As a result, _fields was always assigned an empty string inside build_embed, and the "fields" key never appeared in the embed JSON — making --field a no-op on any system running bash < 4.2.

Fix: replaced ${fields::-1} with ${fields%,}, which strips the trailing comma using suffix pattern removal — a POSIX-compatible feature available in all bash versions.

${fields::-1} requires bash 4.2+ and silently fails on macOS (bash 3.2),
causing fields to never appear in embeds. Replaced with ${fields%,}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant