Skip to content

Commit

Permalink
Merge pull request #25144 from sharkyze/configs/fix-looksLikeSentence…
Browse files Browse the repository at this point in the history
…s-index-out-of-range

config/name_values: fix index out of range in looksLikeSentences
  • Loading branch information
jbardin authored Jun 8, 2020
2 parents fdfe7e5 + 5dfc266 commit ea0b4df
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion configs/named_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func looksLikeSentences(s string) bool {
}
runes := []rune(s) // HCL guarantees that all strings are valid UTF-8
first := runes[0]
last := runes[len(s)-1]
last := runes[len(runes)-1]

// If the first rune is a letter then it must be an uppercase letter.
// (This will only see the first rune in a multi-rune combining sequence,
Expand Down
33 changes: 33 additions & 0 deletions configs/named_values_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package configs

import (
"testing"
)

func Test_looksLikeSentences(t *testing.T) {
tests := map[string]struct {
args string
want bool
}{
"empty sentence": {
args: "",
want: false,
},
"valid sentence": {
args: "A valid sentence.",
want: true,
},
"valid sentence with an accent": {
args: `A Valid sentence with an accent "é".`,
want: true,
},
}

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if got := looksLikeSentences(tt.args); got != tt.want {
t.Errorf("looksLikeSentences() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit ea0b4df

Please sign in to comment.