Skip to content

Substitute empty match in ${var/foo/bar} - #244

Merged
magicant merged 1 commit into
trunkfrom
matching-empty-string
Jul 29, 2026
Merged

Substitute empty match in ${var/foo/bar}#244
magicant merged 1 commit into
trunkfrom
matching-empty-string

Conversation

@magicant

Copy link
Copy Markdown
Owner

The xfnm_subst function performed substitution of an empty match only when XFNM_HEADTAIL was set, which was not consistent with the behavior for other flags. This commit changes the function to always substitute an empty match like any other match, and when substituting all matches, one character is skipped after each empty match to ensure progress. This allows ${var/#/prefix} and ${var/%/suffix} to prefix and suffix the value, respectively.

Fixes #243

@magicant magicant self-assigned this Jul 27, 2026
The xfnm_subst function performed substitution of an empty match only
when XFNM_HEADTAIL was set, which was not consistent with the behavior
for other flags. This commit changes the function to always substitute
an empty match like any other match, and when substituting all matches,
one character is skipped after each empty match to ensure progress. This
allows `${var/#/prefix}` and `${var/%/suffix}` to prefix and suffix the
value, respectively.
@magicant
magicant force-pushed the matching-empty-string branch from aba17fd to 2759232 Compare July 28, 2026 13:30
@magicant
magicant merged commit b941012 into trunk Jul 29, 2026
6 checks passed
@magicant
magicant deleted the matching-empty-string branch July 29, 2026 13:18
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.

Align ${var/#/prefix} and ${var/%/suffix} with ksh93/bash/zsh

1 participant