Skip to content

Commit d09396a

Browse files
authored
fix: more lenient colon-separated field parsing (#254)
Signed-off-by: Yukihiro KAWADA <warp.kawada@gmail.com>
1 parent f6e45fd commit d09396a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

spdx/v2/common/annotation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ func (a *Annotator) UnmarshalJSON(data []byte) error {
2222
annotatorStr := string(data)
2323
annotatorStr = strings.Trim(annotatorStr, "\"")
2424

25-
annotatorFields := strings.SplitN(annotatorStr, ": ", 2)
25+
annotatorFields := strings.SplitN(annotatorStr, ":", 2)
2626

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

31-
a.AnnotatorType = annotatorFields[0]
32-
a.Annotator = annotatorFields[1]
31+
a.AnnotatorType = strings.TrimSpace(annotatorFields[0])
32+
a.Annotator = strings.TrimSpace(annotatorFields[1])
3333

3434
return nil
3535
}

spdx/v2/common/creation_info.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ type Creator struct {
2222
func (c *Creator) UnmarshalJSON(data []byte) error {
2323
str := string(data)
2424
str = strings.Trim(str, "\"")
25-
fields := strings.SplitN(str, ": ", 2)
25+
fields := strings.SplitN(str, ":", 2)
2626

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

31-
c.CreatorType = fields[0]
32-
c.Creator = fields[1]
31+
c.CreatorType = strings.TrimSpace(fields[0])
32+
c.Creator = strings.TrimSpace(fields[1])
3333

3434
return nil
3535
}

spdx/v2/common/package.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func (s *Supplier) UnmarshalJSON(data []byte) error {
2828
return nil
2929
}
3030

31-
supplierFields := strings.SplitN(supplierStr, ": ", 2)
31+
supplierFields := strings.SplitN(supplierStr, ":", 2)
3232

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

37-
s.SupplierType = supplierFields[0]
38-
s.Supplier = supplierFields[1]
37+
s.SupplierType = strings.TrimSpace(supplierFields[0])
38+
s.Supplier = strings.TrimSpace(supplierFields[1])
3939

4040
return nil
4141
}

0 commit comments

Comments
 (0)