Skip to content

Commit c84665c

Browse files
committed
fix(completions): convert key to lowercase if caseSensitive is false
1 parent 3f5d9f4 commit c84665c

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99
### Added
10-
- Add `--show-ip-addresses` flag to `server list` command to optionally include IP addresses in command output.
10+
- Add `--show-ip-addresses` flag to `server list` command to optionally include IP addresses in command output.
11+
12+
### Fixed
13+
- Complete shell input with uppercase letters (e.g., `Cap` to `CapitalizedName` will now work)
1114

1215
## [1.4.0] - 2022-06-15
1316
### Added

internal/completion/helpers.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import (
99
func MatchStringPrefix(vals []string, key string, caseSensitive bool) []string {
1010
var r []string
1111
key = strings.Trim(key, "'\"")
12-
if caseSensitive {
13-
key = strings.ToLower(key)
14-
}
12+
1513
for _, v := range vals {
1614
if (caseSensitive && strings.HasPrefix(v, key)) ||
17-
(!caseSensitive && strings.HasPrefix(strings.ToLower(v), key)) ||
15+
(!caseSensitive && strings.HasPrefix(strings.ToLower(v), strings.ToLower(key))) ||
1816
key == "" {
1917
r = append(r, Escape(v))
2018
}

internal/completion/helpers_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ func TestMatchStringPrefix(t *testing.T) {
3030
caseSensitive: true,
3131
expected: []string{"aba"},
3232
},
33+
{
34+
name: "capitalized",
35+
vals: []string{"Capitalized", "capitalized"},
36+
key: "Cap",
37+
caseSensitive: true,
38+
expected: []string{"Capitalized"},
39+
},
3340
{
3441
name: "doublequotedkey",
3542
vals: []string{"aba", "bba", "cba"},
@@ -52,12 +59,19 @@ func TestMatchStringPrefix(t *testing.T) {
5259
expected: []string{"aba"},
5360
},
5461
{
55-
name: "case insensitive",
62+
name: "case insensitive (lowercase key)",
5663
vals: []string{"aba", "aBa", "Aba", "aab"},
5764
key: "ab",
5865
caseSensitive: false,
5966
expected: []string{"aba", "aBa", "Aba"},
6067
},
68+
{
69+
name: "case insensitive (uppercase key)",
70+
vals: []string{"aba", "aBa", "Aba", "aab"},
71+
key: "AB",
72+
caseSensitive: false,
73+
expected: []string{"aba", "aBa", "Aba"},
74+
},
6175
{
6276
name: "escaped output",
6377
vals: []string{"a a ", "a(0)", "aab", "a;<!`'", "bbb"},

0 commit comments

Comments
 (0)