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

fix correct file format parsing #379

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

viveksahu26
Copy link
Collaborator

@viveksahu26 viveksahu26 commented Dec 31, 2024

closes: #353

This PR addresses the following:

Previously, it was assumed that if decoding failed, the file format must be incorrect. However, decoding failures can occur for several reasons:

  • Invalid format (expected case).
  • Structural or syntax errors in the content (unexpected case).
  • Empty or malformed content (e.g., newline-only content).

For example, a user-provided SBOM in JSON format with a content error (newline characters) was incorrectly assumed to be a non-JSON file because decoding failed. This was a misconception.

To address this, the format is now validated first:

  • If the content starts with "{" or "[", it is identified as JSON.
  • If the content starts with ":" or "-", it is identified as YAML.

Once the format is determined, the corresponding switch-case for JSON or YAML is executed. Any subsequent decoding failures are correctly identified as content issues rather than format misidentification. This ensures more robust and accurate handling of SBOM files.

Signed-off-by: Vivek Kumar Sahu <[email protected]>
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 this pull request may close these issues.

A JSON file containing raw newline characters does not produce an error
1 participant