File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ func (f files) AsSecrets() string {
154154// {{ range .Files.Lines "foo/bar.html" }}
155155// {{ . }}{{ end }}
156156func (f files ) Lines (path string ) []string {
157- if f == nil || f [path ] == nil {
157+ if f == nil || len ( f [path ]) == 0 {
158158 return []string {}
159159 }
160160 s := string (f [path ])
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ var cases = []struct {
3030 {"story/author.txt" , "Joseph Conrad" },
3131 {"multiline/test.txt" , "bar\n foo\n " },
3232 {"multiline/test_with_blank_lines.txt" , "bar\n foo\n \n \n " },
33+ {"empty/empty.txt" , "" },
34+ {"empty/newline_only.txt" , "\n " },
3335}
3436
3537func getTestFiles () files {
@@ -109,3 +111,31 @@ func TestBlankLines(t *testing.T) {
109111 as .Equal ("bar" , out [0 ])
110112 as .Equal ("" , out [3 ])
111113}
114+
115+ func TestLinesEmptyFile (t * testing.T ) {
116+ as := assert .New (t )
117+
118+ f := getTestFiles ()
119+
120+ out := f .Lines ("empty/empty.txt" )
121+ as .Empty (out )
122+ }
123+
124+ func TestLinesNewlineOnlyFile (t * testing.T ) {
125+ as := assert .New (t )
126+
127+ f := getTestFiles ()
128+
129+ out := f .Lines ("empty/newline_only.txt" )
130+ as .Len (out , 1 )
131+ as .Empty (out [0 ])
132+ }
133+
134+ func TestLinesMissingFile (t * testing.T ) {
135+ as := assert .New (t )
136+
137+ f := getTestFiles ()
138+
139+ out := f .Lines ("nonexistent.txt" )
140+ as .Empty (out )
141+ }
You can’t perform that action at this time.
0 commit comments