Skip to content

Commit 3049c53

Browse files
authored
fix: make ParseStream() return the struct, not the pointer (#274)
1 parent 2db998f commit 3049c53

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

parser.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (p *Parser) ParseStream(in io.Reader) (PublicCode, error) { //nolint:mainti
270270

271271
// Return early because proceeding with no base URL would result in a lot
272272
// of duplicate errors stemming from its absence.
273-
return publiccode, ve
273+
return asPublicCode(publiccode), ve
274274
}
275275

276276
p.currentBaseURL = rawRoot
@@ -282,7 +282,7 @@ func (p *Parser) ParseStream(in io.Reader) (PublicCode, error) { //nolint:mainti
282282
if err != nil {
283283
ve = append(ve, newValidationError("", fmt.Sprintf("no baseURL set and failed to get working directory: %s", err)))
284284

285-
return publiccode, ve
285+
return asPublicCode(publiccode), ve
286286
}
287287

288288
p.currentBaseURL = &url.URL{Scheme: "file", Path: cwd}
@@ -322,10 +322,10 @@ func (p *Parser) ParseStream(in io.Reader) (PublicCode, error) { //nolint:mainti
322322
}
323323

324324
if len(ve) == 0 {
325-
return publiccode, nil
325+
return asPublicCode(publiccode), nil
326326
}
327327

328-
return publiccode, ve
328+
return asPublicCode(publiccode), ve
329329
}
330330

331331
func (p *Parser) Parse(uri string) (PublicCode, error) {
@@ -360,6 +360,16 @@ func (p *Parser) Parse(uri string) (PublicCode, error) {
360360
return p.ParseStream(stream)
361361
}
362362

363+
// Ensure the returned value implements PublicCode as a struct, not as a pointer
364+
func asPublicCode(pc PublicCode) PublicCode {
365+
switch v := pc.(type) {
366+
case *PublicCodeV0:
367+
return *v
368+
default:
369+
return v
370+
}
371+
}
372+
363373
func getNodes(key string, node *yaml.Node) (*yaml.Node, *yaml.Node) {
364374
for i := 0; i < len(node.Content); i += 2 {
365375
childNode := *node.Content[i]

0 commit comments

Comments
 (0)