Skip to content

Commit

Permalink
Specifying UTF-8 for SPDX and CycloneDX documents.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevespringett committed Apr 27, 2018
1 parent 767b1a9 commit 1dcce84
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -65,7 +66,7 @@ public SpdxDocumentParser(QueryManager qm) {
}

public List<Component> parse(byte[] spdx) throws ParseException {
final String spdxString = new String(spdx);
final String spdxString = new String(spdx, StandardCharsets.UTF_8);
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(spdx)) {
if (spdxString.contains("<rdf:RDF") && spdxString.contains("http://www.w3.org/1999/02/22-rdf-syntax-ns")) {
return parse(inputStream, DocumentType.RDF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.owasp.dependencytrack.parser.dependencycheck.resolver.ComponentResolver;
import org.owasp.dependencytrack.parser.spdx.rdf.SpdxDocumentParser;
import org.owasp.dependencytrack.persistence.QueryManager;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -62,7 +64,7 @@ public void inform(Event e) {
final List<Component> existingProjectDependencies = new ArrayList<>();
qm.getAllDependencies(project).forEach(item -> existingProjectDependencies.add(item.getComponent()));

final String bomString = new String(bomBytes);
final String bomString = new String(bomBytes, StandardCharsets.UTF_8);
if (bomString.startsWith("<?xml") && bomString.contains("<bom") && bomString.contains("http://cyclonedx.org/schema/bom")) {
final CycloneDxParser parser = new CycloneDxParser(qm);
components = parser.convert(parser.parse(bomBytes));
Expand Down

0 comments on commit 1dcce84

Please sign in to comment.