Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Package FilesAnalyzed field does not behave according to spec #145

Open
ianling opened this issue Jun 3, 2022 · 2 comments
Open

Bug: Package FilesAnalyzed field does not behave according to spec #145

ianling opened this issue Jun 3, 2022 · 2 comments

Comments

@ianling
Copy link
Collaborator

ianling commented Jun 3, 2022

Per the spec, if the FilesAnalyzed field is absent from a document, that should be interpreted as FilesAnalyzed: true.

Unfortunately, for the JSON and YAML parsers/savers, this was missed, so if they are absent, they default to false.

Additionally, the zero/empty value of a boolean in Go is false, and the FilesAnalyzed field's JSON tag contains omitempty, so we are unable to write out the FilesAnalyzed field to a file if it is false; it will simply be omitted, which results in other things (like the online SPDX validator tool) interpreting it as true.

We should change this field to a pointer to denote that it can be absent, and also make sure that we handle that case properly by interpreting it as true across all the different file parsers.

@ianling
Copy link
Collaborator Author

ianling commented Jun 3, 2022

I am handling this

@swinslow
Copy link
Member

swinslow commented Jun 5, 2022

Thanks @ianling. For what it's worth, the way I addressed this in the original tag-value code and SPDX model for the Golang tools was to add a second parameter, IsFilesAnalyzedTagPresent:

// 3.8: FilesAnalyzed
// Cardinality: optional, one; default value is "true" if omitted
FilesAnalyzed bool `json:"filesAnalyzed,omitempty"`
// NOT PART OF SPEC: did FilesAnalyzed tag appear?
IsFilesAnalyzedTagPresent bool `json:"-"`

Then, when parsing a document and encountering a new Package section, the default settings for that new Package are:

parser.pkg = &spdx.Package2_2{
FilesAnalyzed: true,
IsFilesAnalyzedTagPresent: false,
}

which then gets overwritten only if a FilesAnalyzed tag actually appears:

case "FilesAnalyzed":
parser.pkg.IsFilesAnalyzedTagPresent = true
if value == "false" {
parser.pkg.FilesAnalyzed = false
} else if value == "true" {
parser.pkg.FilesAnalyzed = true
}

Happy to modify this if there's a more appropriate way to handle, especially given how the JSON / YAML tooling will have to handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants