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

A JSON file containing raw newline characters does not produce an error #353

Open
warpkwd opened this issue Nov 18, 2024 · 4 comments · May be fixed by #356
Open

A JSON file containing raw newline characters does not produce an error #353

warpkwd opened this issue Nov 18, 2024 · 4 comments · May be fixed by #356
Assignees

Comments

@warpkwd
Copy link
Contributor

warpkwd commented Nov 18, 2024

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

I want a JSON file containing raw newline characters to trigger a parser error, but it does not.
While the JSON parser does report an error, it proceeds to the next step without halting,
where the file appears to be accepted and processed as YAML format instead.

2024-11-18T21:50:44.234+0900    DEBUG   engine/compliance.go:30 engine.ComplianceRun()
2024-11-18T21:50:44.255+0900    DEBUG   engine/compliance.go:36 Config: &{Path:[samples/c.json] Categories:[] Features:[] JSON:false Basic:false Detailed:false Pdf:false Spdx:false Cdx:false Recurse:false Debug:true ConfigPath: Ntia:true Bsi:false Oct:false Fsct:false Color:false}
2024-11-18T21:50:44.255+0900    DEBUG   engine/compliance.go:84 engine.getSbomDocument()
2024-11-18T21:50:44.256+0900    DEBUG   sbom/sbom.go:177        SBOM detect spec:spdx format:yaml
2024-11-18T21:50:44.260+0900    DEBUG   compliance/compliance.go:47     compliance.ComplianceResult()
2024-11-18T21:50:44.260+0900    DEBUG   compliance/ntia.go:43   compliance.ntiaResult()
2024-11-18T21:50:44.266+0900    DEBUG   engine/compliance.go:78 Compliance Report: samples/c.json
@warpkwd
Copy link
Contributor Author

warpkwd commented Nov 18, 2024

func detectSbomFormat(f io.ReadSeeker) (SpecFormat, FileFormat, FormatVersion, error) {
   :

here it is.

@viveksahu26
Copy link
Collaborator

Hey @warpkwd , can you provide that json file ?

@warpkwd
Copy link
Contributor Author

warpkwd commented Nov 18, 2024

tt.json

$ sbomqs compliance -n -D tt.json 2>err
Compliance score by Interlynk Score:4.1 RequiredScore:4.1 OptionalScore:0.0 for tt.json
* indicates optional fields
+-------------------------------------+------------+--------------------------------+------------------------------------------------------------------+-------+
|             ELEMENT ID              | SECTION ID |     NTIA MINIMUM ELEMENTS      |                              RESULT                              | SCORE |
+-------------------------------------+------------+--------------------------------+------------------------------------------------------------------+-------+
| Automation Support                  |        1.1 | Machine-Readable Formats       | spdx, yaml                                                       |  10.0 |
+-------------------------------------+------------+--------------------------------+------------------------------------------------------------------+-------+
| SBOM Data Fields                    |        2.1 | Author                         | Yukihiro Kawada                                                  |  10.0 |
+                                     +------------+--------------------------------+------------------------------------------------------------------+-------+
|                                     |        2.2 | Timestamp                      | 2023-01-12T22:06:03Z                                             |  10.0 |
+                                     +------------+--------------------------------+------------------------------------------------------------------+-------+


$ cat err
2024-11-19T06:50:38.984+0900    DEBUG   engine/compliance.go:30 engine.ComplianceRun()
2024-11-19T06:50:39.005+0900    DEBUG   engine/compliance.go:36 Config: &{Path:[tt.json] Categories:[] Features:[] JSON:false Basic:false Detailed:false Pdf:false Spdx:false Cdx:false Recurse:false Debug:true ConfigPath: Ntia:true Bsi:false Oct:false Fsct:false Color:false}
2024-11-19T06:50:39.005+0900    DEBUG   engine/compliance.go:84 engine.getSbomDocument()
2024-11-19T06:50:39.007+0900    DEBUG   sbom/sbom.go:176        SBOM detect spec:spdx format:yaml
2024-11-19T06:50:39.012+0900    DEBUG   compliance/compliance.go:47     compliance.ComplianceResult()
2024-11-19T06:50:39.013+0900    DEBUG   compliance/ntia.go:43   compliance.ntiaResult()
2024-11-19T06:50:39.055+0900    DEBUG   engine/compliance.go:78 Compliance Report: tt.json

@viveksahu26
Copy link
Collaborator

viveksahu26 commented Nov 19, 2024

Yes, the error is correct:
NOTE: I updated the code to get this error. So you will find this in main code.

$ go run main.go compliance -n -D  tt.json 

2024-11-19T09:52:21.981+0530	DEBUG	engine/compliance.go:30	engine.ComplianceRun()
2024-11-19T09:52:21.981+0530	DEBUG	engine/compliance.go:36	Config: &{Path:[tt.json] Categories:[] Features:[] JSON:false Basic:false Detailed:false Pdf:false Spdx:false Cdx:false Recurse:false Debug:true ConfigPath: Ntia:true Bsi:false Oct:false Fsct:false Color:false}
2024-11-19T09:52:21.981+0530	DEBUG	engine/compliance.go:84	engine.getSbomDocument()
err1:  invalid character '\n' in string literal
err4(NewSBOMDocument) :  invalid character '\n' in string literal
err:  invalid character '\n' in string literal
2024-11-19T09:52:21.982+0530	DEBUG	engine/compliance.go:134	failed to create sbom document for  :tt.json

2024-11-19T09:52:21.982+0530	DEBUG	engine/compliance.go:135	invalid character '\n' in string literal

failed to parse tt.json : invalid character '\n' in string literal
2024-11-19T09:52:21.982+0530	DEBUG	engine/compliance.go:40	getSbomDocument failed for file :tt.json

failed to get sbom document for tt.json
Error: invalid character '\n' in string literal

@viveksahu26 viveksahu26 self-assigned this Nov 19, 2024
@viveksahu26 viveksahu26 linked a pull request Nov 19, 2024 that will close this issue
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