fix(completion): use greedy %% for colon parsing in bash completion template#2336
Open
TimSoethout wants to merge 1 commit into
Open
fix(completion): use greedy %% for colon parsing in bash completion template#2336TimSoethout wants to merge 1 commit into
TimSoethout wants to merge 1 commit into
Conversation
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.
What type of PR is this?
What this PR does / why we need it
The bash autocomplete template in
autocomplete/bash_autocompleteusesfmt.Sprintffor rendering. The line that extracts the token fromtoken:descriptionformat had:token="${line%%:*}"Because
fmt.Sprintfinterprets%%as an escape for a literal%, the rendered output becomes${line%:*}(single%). In bash,${line%:*}removes the shortest suffix matching:*— i.e. it strips from the last colon. This is wrong when descriptions contain colons (e.g.export:Export configs such as: compose-config), causing the description text to leak intocompgen -Wand produce spurious completions.The fix changes
%%to%%%%in the template so that afterfmt.Sprintf, the rendered script contains%%(greedy removal from the first colon):Which issue(s) this PR fixes
Fixes #2335
Testing
Added
TestCompletionBashGreedyColonParsingregression test that renders the bash completion template and verifies the output contains${line%%:*}(greedy) and not${line%:*}(non-greedy).Release Notes