mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
strip trailing newline from Files.Lines
Signed-off-by: Joe Julian <me@joejulian.name>
This commit is contained in:
parent
e63083492b
commit
b3707e666b
2 changed files with 20 additions and 4 deletions
|
|
@ -131,7 +131,7 @@ func (f files) AsConfig() string {
|
|||
//
|
||||
// data:
|
||||
//
|
||||
// {{ .Files.Glob("secrets/*").AsSecrets() }}
|
||||
// {{ .Files.Glob("secrets/*").AsSecrets() | indent 4 }}
|
||||
func (f files) AsSecrets() string {
|
||||
if f == nil {
|
||||
return ""
|
||||
|
|
@ -157,6 +157,9 @@ func (f files) Lines(path string) []string {
|
|||
if f == nil || f[path] == nil {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
return strings.Split(string(f[path]), "\n")
|
||||
s := string(f[path])
|
||||
if s[len(s)-1] == '\n' {
|
||||
s = s[:len(s)-1]
|
||||
}
|
||||
return strings.Split(s, "\n")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ var cases = []struct {
|
|||
{"ship/stowaway.txt", "Legatt"},
|
||||
{"story/name.txt", "The Secret Sharer"},
|
||||
{"story/author.txt", "Joseph Conrad"},
|
||||
{"multiline/test.txt", "bar\nfoo"},
|
||||
{"multiline/test.txt", "bar\nfoo\n"},
|
||||
{"multiline/test_with_blank_lines.txt", "bar\nfoo\n\n\n"},
|
||||
}
|
||||
|
||||
func getTestFiles() files {
|
||||
|
|
@ -96,3 +97,15 @@ func TestLines(t *testing.T) {
|
|||
|
||||
as.Equal("bar", out[0])
|
||||
}
|
||||
|
||||
func TestBlankLines(t *testing.T) {
|
||||
as := assert.New(t)
|
||||
|
||||
f := getTestFiles()
|
||||
|
||||
out := f.Lines("multiline/test_with_blank_lines.txt")
|
||||
as.Len(out, 4)
|
||||
|
||||
as.Equal("bar", out[0])
|
||||
as.Equal("", out[3])
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue