Skip to content

Commit

Permalink
add support to ; for comments in unit files as per systemd document…
Browse files Browse the repository at this point in the history
…ation

Signed-off-by: Ahmed Moalla <ahmed.moalla@gmail.com>
  • Loading branch information
AhmedMoalla committed Jan 10, 2025
1 parent 1a00c92 commit 2528334
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/systemd/parser/unitfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (f *UnitFile) Dup() *UnitFile {
}

func lineIsComment(line string) bool {
return len(line) == 0 || line[0] == '#' || line[0] == ':'
return len(line) == 0 || line[0] == '#' || line[0] == ':' || line[0] == ';'
}

func lineIsGroup(line string) bool {
Expand Down
29 changes: 29 additions & 0 deletions pkg/systemd/parser/unitfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,35 @@ func TestUnitDropinPaths_Search(t *testing.T) {
}
}

func TestCommentsIgnored(t *testing.T) {
unitWithComments := `[Container]
# comment
Name=my-container
: second comment
; another comment
`
f := NewUnitFile()
if e := f.Parse(unitWithComments); e != nil {
panic(e)
}

groups := f.ListGroups()
assert.Len(t, groups, 1)
assert.Equal(t, "Container", groups[0])

comments := make([]string, 0, 2)
for _, line := range f.groups[0].lines {
if line.isComment {
comments = append(comments, line.value)
}
}

assert.Len(t, comments, 3)
assert.Equal(t, "# comment", comments[0])
assert.Equal(t, ": second comment", comments[1])
assert.Equal(t, "; another comment", comments[2])
}

func FuzzParser(f *testing.F) {
for _, sample := range samples {
f.Add([]byte(sample))
Expand Down

0 comments on commit 2528334

Please sign in to comment.