Skip to content

Commit

Permalink
feat: return error when parsing unknown spec versions
Browse files Browse the repository at this point in the history
Signed-off-by: nscuro <nscuro@protonmail.com>
  • Loading branch information
nscuro committed Sep 28, 2022
1 parent c2db05e commit 7415143
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cyclonedx.go
Expand Up @@ -19,6 +19,7 @@ package cyclonedx

import (
"encoding/xml"
"errors"
"fmt"
"regexp"
)
Expand All @@ -29,6 +30,8 @@ const (
BOMFormat = "CycloneDX"
)

var ErrInvalidSpecVersion = errors.New("invalid specification version")

type Advisory struct {
Title string `json:"title,omitempty" xml:"title,omitempty"`
URL string `json:"url" xml:"url"`
Expand Down
6 changes: 5 additions & 1 deletion cyclonedx_json.go
Expand Up @@ -17,7 +17,9 @@

package cyclonedx

import "encoding/json"
import (
"encoding/json"
)

func (sv SpecVersion) MarshalJSON() ([]byte, error) {
return json.Marshal(sv.String())
Expand All @@ -41,6 +43,8 @@ func (sv *SpecVersion) UnmarshalJSON(bytes []byte) error {
*sv = SpecVersion1_3
case SpecVersion1_4.String():
*sv = SpecVersion1_4
default:
return ErrInvalidSpecVersion
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions cyclonedx_xml.go
Expand Up @@ -183,6 +183,8 @@ func (sv *SpecVersion) UnmarshalXML(d *xml.Decoder, start xml.StartElement) erro
*sv = SpecVersion1_3
case SpecVersion1_4.String():
*sv = SpecVersion1_4
default:
return ErrInvalidSpecVersion
}

return nil
Expand Down

0 comments on commit 7415143

Please sign in to comment.