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

feat: cli option to disable html escaping in output #569

Merged
merged 3 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 37 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,20 @@ Examples:
$ cyclonedx-gomod app -json -output acme-app.bom.json -packages -files -licenses -main cmd/acme-app /usr/src/acme-module

FLAGS
-assert-licenses=false Assert detected licenses
-files=false Include files
-json=false Output in JSON
-licenses=false Perform license detection
-main string Path to the application's main package, relative to MODULE_PATH
-noserial=false Omit serial number
-output - Output file path (or - for STDOUT)
-output-version 1.6 Output spec verson (1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0)
-packages=false Include packages
-paths=false Include file paths relative to their module root
-serial string Serial number
-std=false Include Go standard library as component and dependency of the module
-verbose=false Enable verbose output
-assert-licenses=false Assert detected licenses
-files=false Include files
-json=false Output in JSON
-disable-html-escape=false Disable HTML escaping in JSON output
-licenses=false Perform license detection
-main string Path to the application's main package, relative to MODULE_PATH
-noserial=false Omit serial number
-output - Output file path (or - for STDOUT)
-output-version 1.6 Output spec verson (1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0)
-packages=false Include packages
-paths=false Include file paths relative to their module root
-serial string Serial number
-std=false Include Go standard library as component and dependency of the module
-verbose=false Enable verbose output
```

#### `bin`
Expand Down Expand Up @@ -179,16 +180,17 @@ Example:
$ cyclonedx-gomod bin -json -output acme-app-v1.0.0.bom.json -version v1.0.0 ./acme-app

FLAGS
-assert-licenses=false Assert detected licenses
-json=false Output in JSON
-licenses=false Perform license detection
-noserial=false Omit serial number
-output - Output file path (or - for STDOUT)
-output-version 1.6 Output spec verson (1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0)
-serial string Serial number
-std=false Include Go standard library as component and dependency of the module
-verbose=false Enable verbose output
-version string Version of the main component
-assert-licenses=false Assert detected licenses
-json=false Output in JSON
-disable-html-escape=false Disable HTML escaping in JSON output
-licenses=false Perform license detection
-noserial=false Omit serial number
-output - Output file path (or - for STDOUT)
-output-version 1.6 Output spec verson (1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0)
-serial string Serial number
-std=false Include Go standard library as component and dependency of the module
-verbose=false Enable verbose output
-version string Version of the main component
```

#### `mod`
Expand All @@ -212,17 +214,18 @@ Examples:
$ cyclonedx-gomod mod -test -output bom.xml ./cyclonedx-go

FLAGS
-assert-licenses=false Assert detected licenses
-json=false Output in JSON
-licenses=false Perform license detection
-noserial=false Omit serial number
-output - Output file path (or - for STDOUT)
-output-version 1.6 Output spec verson (1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0)
-serial string Serial number
-std=false Include Go standard library as component and dependency of the module
-test=false Include test dependencies
-type application Type of the main component
-verbose=false Enable verbose output
-assert-licenses=false Assert detected licenses
-json=false Output in JSON
-disable-html-escape=false Disable HTML escaping in JSON output
-licenses=false Perform license detection
-noserial=false Omit serial number
-output - Output file path (or - for STDOUT)
-output-version 1.6 Output spec verson (1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0)
-serial string Serial number
-std=false Include Go standard library as component and dependency of the module
-test=false Include test dependencies
-type application Type of the main component
-verbose=false Enable verbose output
```

### Examples 📃
Expand Down
8 changes: 5 additions & 3 deletions internal/cli/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ func (l LogOptions) Validate() error {

// OutputOptions provides options for customizing the output.
type OutputOptions struct {
OutputFilePath string
OutputVersion string
UseJSON bool
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
Loading