mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
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:
@@ -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 ""
|
||||
|
||||
Reference in New Issue
Block a user