diff --git a/scanner/suse.go b/scanner/suse.go index 52b6d8be0b..6fc67f3f0f 100644 --- a/scanner/suse.go +++ b/scanner/suse.go @@ -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 @@ -248,6 +264,9 @@ func (o *suse) parseZypperLUOneLine(line string) (*models.Package, error) { return nil, xerrors.Errorf("zypper -q lu Unknown format: %s", line) } available := strings.Split(strings.TrimSpace(ss[4]), "-") + if len(available) != 2 { + return nil, xerrors.Errorf("unexpected Available Version. expected: %q, actual: %q", "-", strings.TrimSpace(ss[4])) + } return &models.Package{ Name: strings.TrimSpace(ss[2]), NewVersion: available[0], diff --git a/scanner/suse_test.go b/scanner/suse_test.go index 6da55f53d1..0393d5ec03 100644 --- a/scanner/suse_test.go +++ b/scanner/suse_test.go @@ -68,6 +68,22 @@ v | Update repository with updates from SUSE Linux Enterprise 15 | git-core | 2. }, }, }, + { + name: "table header", + 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) {