Skip to content

Commit

Permalink
Merge pull request #86 from fnxpt/fixNullByteString
Browse files Browse the repository at this point in the history
fix issue with null byte string by dumping it first
  • Loading branch information
macblazer authored Jan 7, 2025
2 parents d39e38e + 9a000b2 commit 93c3904
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cyclonedx/cocoapods/bom_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def add_to_bom(xml, manifest_path, trim_strings_length = 0)
xml_add_author(xml, trim_strings_length)
xml.name_ name
xml.version version.to_s
xml.description { xml.cdata description } unless description.nil?
# Use `dump` to escape non-printing characters, then remove the starting/trailing double-quotes from `dump`.
xml.description { xml.cdata description.dump[1..-2] } unless description.nil?
unless checksum.nil?
xml.hashes do
xml.hash_(checksum, alg: CHECKSUM_ALGORITHM)
Expand Down
11 changes: 11 additions & 0 deletions spec/cyclonedx/cocoapods/bom_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@
end
end

context 'when having a null byte description' do
let(:pod) do
described_class.new(name: pod_name, version: pod_version, checksum: checksum).populate(summary: "'\0'")
end

it 'should generate a correct component description' do
expect(xml.at('/component/description')).not_to be_nil
expect(xml.at('/component/description').text).to eql("'\\x00'")
end
end

context 'when not having a checksum' do
let(:pod) { described_class.new(name: pod_name, version: pod_version) }

Expand Down

0 comments on commit 93c3904

Please sign in to comment.