pull/32280/merge
Shudhanshu Singh 10 hours ago committed by GitHub
commit 2118600e4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -154,12 +154,10 @@ func (f files) AsSecrets() string {
// {{ range .Files.Lines "foo/bar.html" }}
// {{ . }}{{ end }}
func (f files) Lines(path string) []string {
if f == nil || f[path] == nil {
if f == nil || len(f[path]) == 0 {
return []string{}
}
s := string(f[path])
if s[len(s)-1] == '\n' {
s = s[:len(s)-1]
}
s = strings.TrimSuffix(s, "\n")
return strings.Split(s, "\n")
}

@ -30,6 +30,7 @@ var cases = []struct {
{"story/author.txt", "Joseph Conrad"},
{"multiline/test.txt", "bar\nfoo\n"},
{"multiline/test_with_blank_lines.txt", "bar\nfoo\n\n\n"},
{"multiline/empty.txt", ""},
}
func getTestFiles() files {
@ -94,8 +95,13 @@ func TestLines(t *testing.T) {
out := f.Lines("multiline/test.txt")
as.Len(out, 2)
as.Equal("bar", out[0])
outEmpty := f.Lines("multiline/empty.txt")
as.Len(outEmpty, 0)
outNonExistent := f.Lines("nonexistent.txt")
as.Len(outNonExistent, 0)
}
func TestBlankLines(t *testing.T) {

Loading…
Cancel
Save