No tilde expansion in subst in double-quoted parameter#177
Merged
Conversation
If a parameter expansion with a PT_MINUS, PT_PLUS, PT_ASSIGN, or
PT_ERROR type is in double quotes, tilde expansion is not performed
on the substitution part of the expansion. This is what is specified
in POSIX.1-2024 XCU 2.2.3:
> For parameter expansions other than the four varieties that provide
> for substring processing, within the string of characters from an
> enclosed "${" to the matching '}', the double-quotes within which the
> expansion occurs shall preserve the literal value of all characters,
> with the exception of the characters double-quote, backquote,
> <dollar-sign>, and <backslash>.
Fixes #175
See also commit 4eccc94, which addressed a similar issue for single
quotes.
There was a problem hiding this comment.
Pull Request Overview
A fix for POSIX-compliant tilde expansion behavior in double-quoted parameter substitutions and corresponding test and documentation updates.
- Disable tilde expansion in the
wordpart of${foo+word},${foo-word},${foo=word}, and${foo?word}when double-quoted. - Update
expand_param,expand_single, andprint_subst_as_errorto respect the new tilde rules. - Add tests and update release notes (
NEWS,NEWS.ja) to document and verify the change.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/quote-p.tst | Added tests (test_oE) covering tilde expansion in double-quoted parameter substitutions |
| expand.c | Introduced substt flag, updated calls to expand_four/expand_single, and modified print_subst_as_error signature |
| NEWS | Documented the tilde expansion bug fix in the English release notes (typo present) |
| NEWS.ja | Documented the tilde expansion change in the Japanese release notes |
Comments suppressed due to low confidence (1)
expand.c:1102
- Add the
statickeyword to the definition ofprint_subst_as_errorso it matches its forward declaration and retains internal linkage.
void print_subst_as_error(const paramexp_T *p, tildetype_T tilde, quoting_T quoting)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a parameter expansion with a PT_MINUS, PT_PLUS, PT_ASSIGN, or PT_ERROR type is in double quotes, tilde expansion is not performed on the substitution part of the expansion. This is what is specified in POSIX.1-2024 XCU 2.2.3:
Fixes #175
See also commit 4eccc94, which addressed a similar issue for single quotes.
This pull request does not address the issue of whether tilde expansion should apply to each colon-separated tilde prefix or only to the initial part of the substitution word in an unquoted parameter expansion in an assignment (e.g.,
x=${unset-~:~}) because POSIX is unclear on this issue and existing shells behave differently.Summary by Copilot
This pull request addresses a bug in parameter expansions where tilde expansion was incorrectly performed on the
wordpart of certain expansions, even when enclosed in double quotes. It includes fixes in the core logic of theexpand.cfile and updates to the test suite to ensure the issue is resolved and properly validated.Bug Fixes in Parameter Expansions:
expand_paramandprint_subst_as_errorfunctions to prevent tilde expansion on thewordpart of${foo+word},${foo-word},${foo=word}, and${foo?word}when the expansion is in double quotes. Introducedtildetype_Tto manage tilde behavior. ([[1]](https://github.com/magicant/yash/pull/177/files#diff-4e9f03b0fcb26abe26e8d83441df7ea667ec7e16089a316713421ec74247dce7L80-R81),[[2]](https://github.com/magicant/yash/pull/177/files#diff-4e9f03b0fcb26abe26e8d83441df7ea667ec7e16089a316713421ec74247dce7R882),[[3]](https://github.com/magicant/yash/pull/177/files#diff-4e9f03b0fcb26abe26e8d83441df7ea667ec7e16089a316713421ec74247dce7L893-R895),[[4]](https://github.com/magicant/yash/pull/177/files#diff-4e9f03b0fcb26abe26e8d83441df7ea667ec7e16089a316713421ec74247dce7L916-R918),[[5]](https://github.com/magicant/yash/pull/177/files#diff-4e9f03b0fcb26abe26e8d83441df7ea667ec7e16089a316713421ec74247dce7L941-R943),[[6]](https://github.com/magicant/yash/pull/177/files#diff-4e9f03b0fcb26abe26e8d83441df7ea667ec7e16089a316713421ec74247dce7L1100-R1107))Documentation Updates:
NEWSandNEWS.jafiles to document the bug fix and clarify the behavior of tilde expansion in parameter substitutions. ([[1]](https://github.com/magicant/yash/pull/177/files#diff-7ee66c4f1536ac84dc5bbff1b8312e2eef24b974b3e48a5c5c2bcfdf2eb8f3ceR14-R17),[[2]](https://github.com/magicant/yash/pull/177/files#diff-b87696c2a5e686064d064bd85872d4d5e797abb0a16fd93f6a21593770d9ec81R12-R14))Test Suite Enhancements:
quote-p.tstto validate the correct handling of tilde expansion in parameter substitutions for${a+b},${a-b}, and${a=b}forms. These tests ensure the fix is robust and behaves as expected across different scenarios. ([[1]](https://github.com/magicant/yash/pull/177/files#diff-c6be1aff379ddbac283e4d243fc2f29127956a24d54bf15de46d38e1ddbe0485R606-R612),[[2]](https://github.com/magicant/yash/pull/177/files#diff-c6be1aff379ddbac283e4d243fc2f29127956a24d54bf15de46d38e1ddbe0485R633-R639),[[3]](https://github.com/magicant/yash/pull/177/files#diff-c6be1aff379ddbac283e4d243fc2f29127956a24d54bf15de46d38e1ddbe0485R667-R675))