Skip to content

Commit

Permalink
feat: cli option to disable html escaping in output
Browse files Browse the repository at this point in the history
Signed-off-by: Aswinr24 <[email protected]>
  • Loading branch information
Aswinr24 committed Jan 3, 2025
1 parent 95a600b commit 1747550
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/cli/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type OutputOptions struct {
OutputFilePath string
OutputVersion string
UseJSON bool
DisableHTMLEscape bool
}

func (o *OutputOptions) RegisterFlags(fs *flag.FlagSet) {
Expand All @@ -98,6 +99,7 @@ func (o *OutputOptions) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(&o.OutputFilePath, "output", "-", "Output file path (or - for STDOUT)")
fs.StringVar(&o.OutputVersion, "output-version", cdx.SpecVersion1_6.String(),
fmt.Sprintf("Output spec verson (%s)", strings.Join(versionChoices, ", ")))
fs.BoolVar(&o.DisableHTMLEscape, "disable-html-escape", false, "Disable HTML escaping in JSON output")
}

func (o OutputOptions) Validate() error {
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func WriteBOM(bom *cdx.BOM, outputOptions options.OutputOptions) error {
encoder := cdx.NewBOMEncoder(outputWriter, outputFormat)
encoder.SetPretty(true)

if(outputOptions.DisableHTMLEscape) {
encoder.SetEscapeHTML(false)
}

if err := encoder.EncodeVersion(bom, outputVersion); err != nil {
return fmt.Errorf("failed to encode sbom: %w", err)
}
Expand Down

0 comments on commit 1747550

Please sign in to comment.