Skip to content

Commit

Permalink
fix(scanner/suse): skip table header in zypper -q lu
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n committed Dec 18, 2024
1 parent 635109f commit 3e147ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scanner/suse.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,27 @@ var warnRepoPattern = regexp.MustCompile(`Warning: Repository '.+' appears to be
func (o *suse) parseZypperLULines(stdout string) (models.Packages, error) {
updatables := models.Packages{}
scanner := bufio.NewScanner(strings.NewReader(stdout))
headerParsed := false
for scanner.Scan() {
line := scanner.Text()
if line == "" || strings.Contains(line, "S | Repository") || strings.Contains(line, "--+----------------") || warnRepoPattern.MatchString(line) {
if line == "" || warnRepoPattern.MatchString(line) {
continue
}

if !headerParsed {
if func() bool {
for _, c := range line {
if !strings.ContainsRune("-+", c) {
return false
}
}
return true
}() {
headerParsed = true
}
continue
}

pack, err := o.parseZypperLUOneLine(line)
if err != nil {
return nil, err
Expand Down
16 changes: 16 additions & 0 deletions scanner/suse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ v | Update repository with updates from SUSE Linux Enterprise 15 | git-core | 2.
},
},
},
{
name: "",
args: args{
stdout: `S | Repository | Name | Current Version | Available Version | Arch
---+--------------------------------------------------------------+----------+-----------------+-------------------+-------
v | Update repository with updates from SUSE Linux Enterprise 15 | iproute2 | 5.14-150400.1.8 | 6.4-150600.7.3.1 | x86_64`,
},
want: models.Packages{
"iproute2": {
Name: "iproute2",
NewVersion: "6.4",
NewRelease: "150600.7.3.1",
Arch: "x86_64",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 3e147ae

Please sign in to comment.