Skip to content

Commit

Permalink
fix: more lenient colon-separated field parsing (#254)
Browse files Browse the repository at this point in the history
Signed-off-by: Yukihiro KAWADA <[email protected]>
  • Loading branch information
warpkwd authored Dec 27, 2024
1 parent f6e45fd commit d09396a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions spdx/v2/common/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ func (a *Annotator) UnmarshalJSON(data []byte) error {
annotatorStr := string(data)
annotatorStr = strings.Trim(annotatorStr, "\"")

annotatorFields := strings.SplitN(annotatorStr, ": ", 2)
annotatorFields := strings.SplitN(annotatorStr, ":", 2)

if len(annotatorFields) != 2 {
return fmt.Errorf("failed to parse Annotator '%s'", annotatorStr)
}

a.AnnotatorType = annotatorFields[0]
a.Annotator = annotatorFields[1]
a.AnnotatorType = strings.TrimSpace(annotatorFields[0])
a.Annotator = strings.TrimSpace(annotatorFields[1])

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions spdx/v2/common/creation_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ type Creator struct {
func (c *Creator) UnmarshalJSON(data []byte) error {
str := string(data)
str = strings.Trim(str, "\"")
fields := strings.SplitN(str, ": ", 2)
fields := strings.SplitN(str, ":", 2)

if len(fields) != 2 {
return fmt.Errorf("failed to parse Creator '%s'", str)
}

c.CreatorType = fields[0]
c.Creator = fields[1]
c.CreatorType = strings.TrimSpace(fields[0])
c.Creator = strings.TrimSpace(fields[1])

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions spdx/v2/common/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func (s *Supplier) UnmarshalJSON(data []byte) error {
return nil
}

supplierFields := strings.SplitN(supplierStr, ": ", 2)
supplierFields := strings.SplitN(supplierStr, ":", 2)

if len(supplierFields) != 2 {
return fmt.Errorf("failed to parse Supplier '%s'", supplierStr)
}

s.SupplierType = supplierFields[0]
s.Supplier = supplierFields[1]
s.SupplierType = strings.TrimSpace(supplierFields[0])
s.Supplier = strings.TrimSpace(supplierFields[1])

return nil
}
Expand Down

0 comments on commit d09396a

Please sign in to comment.