Skip to content

Commit ef5dd77

Browse files
committed
Permit space-separated XS-Go-Import-Path
For example: XS-Go-Import-Path: example.com/foo example.com/bar This avoids forcing package maintainers to look up whether a trailing comma after the final item is allowed or not. (Separating by whitespace or permitting a trailing comma makes it easier to construct a readable and VC-friendly multiline list of values.) Spaces cannot exist in a module path, so there is no risk of parsing ambiguity. The `make` subcommand doesn't produce space-separated lists, and `dh-golang` doesn't yet support it, so this is just a step towards generally allowing it everywhere.
1 parent 7b9e55b commit ef5dd77

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

search.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type ftpMasterApiResult struct {
2626
Source string `json:"source"`
2727
}
2828

29+
// Entries in XS-Go-Import-Path are separated by commas and/or spaces.
30+
var listSep = regexp.MustCompile(`[,\s]+`)
31+
2932
type getGolangBinariesConfig struct {
3033
url string
3134
}
@@ -61,13 +64,9 @@ func getGolangBinaries(opts ...getGolangBinariesOption) (map[string]debianPackag
6164
if !strings.HasSuffix(pkg.Binary, "-dev") {
6265
continue // skip -dbgsym packages etc.
6366
}
64-
for _, importPath := range strings.Split(pkg.MetadataValue, ",") {
65-
// XS-Go-Import-Path can be comma-separated and contain spaces.
66-
importPath := strings.TrimSpace(importPath)
67-
// importPath might be the empty string if XS-Go-Import-Path has a leading comma, trailing
68-
// comma, or extraneous internal comma. It might also be empty if api.ftp-master.d.o returns
69-
// packages where XS-Go-Import-Path is explicitly set to the empty string or to a
70-
// whitespace-only string.
67+
for _, importPath := range listSep.Split(pkg.MetadataValue, -1) {
68+
// importPath might be the empty string if XS-Go-Import-Path has a leading or trailing
69+
// listSep, or the entire string matches listSep*.
7170
if importPath == "" {
7271
continue
7372
}

search_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ func TestGetGolangBinaries(t *testing.T) {
165165
},
166166
},
167167
},
168+
{
169+
desc: "whitespace separated",
170+
results: []ftpMasterApiResult{{
171+
Binary: "golang-example-foo-dev",
172+
MetadataValue: "example.com/foo \n\texample.com/bar",
173+
Source: "golang-example-foo",
174+
}},
175+
want: map[string]debianPackage{
176+
"example.com/foo": {
177+
binary: "golang-example-foo-dev",
178+
source: "golang-example-foo",
179+
},
180+
"example.com/bar": {
181+
binary: "golang-example-foo-dev",
182+
source: "golang-example-foo",
183+
},
184+
},
185+
},
168186
} {
169187
t.Run(tc.desc, func(t *testing.T) {
170188
t.Parallel()

0 commit comments

Comments
 (0)