fix(apt): fix extractURL multi-token options parsing and add unit tests

- Fix bug in extractURL where multi-token option blocks like
  [arch=amd64 signed-by=/path/key.gpg] were not properly skipped,
  causing the option value to be returned instead of the URL
- Add comprehensive unit tests for parseList, parseSearch, parseInfo
  edge cases (empty input, missing fields, special characters)
- Add unit tests for normalizeName and parseArch covering all
  supported Debian architectures and edge cases
- Add unit tests for formatTargets, buildArgs (all option combos),
  and extractURL (basic, options, signed-by)
- Coverage: apt package 7.5% -> 17.1%
This commit is contained in:
2026-03-05 09:33:36 +00:00
parent 397e865107
commit 6c8d0d367b
4 changed files with 482 additions and 6 deletions

View File

@@ -271,19 +271,25 @@ func listRepos(_ context.Context) ([]snack.Repository, error) {
// extractURL pulls the URL from a deb/deb-src line.
func extractURL(line string) string {
fields := strings.Fields(line)
inOptions := false
for i, f := range fields {
if i == 0 {
continue // skip deb/deb-src
}
if strings.HasPrefix(f, "[") {
// skip options block
for ; i < len(fields); i++ {
if strings.HasSuffix(fields[i], "]") {
break
}
if inOptions {
if strings.HasSuffix(f, "]") {
inOptions = false
}
continue
}
if strings.HasPrefix(f, "[") {
if strings.HasSuffix(f, "]") {
// Single-token options like [arch=amd64]
continue
}
inOptions = true
continue
}
return f
}
return ""