diff --git a/lib/id3tag/string_util.rb b/lib/id3tag/string_util.rb index ac69e49..4cd7c70 100644 --- a/lib/id3tag/string_util.rb +++ b/lib/id3tag/string_util.rb @@ -20,7 +20,7 @@ def self.undo_unsynchronization(input) end def self.cut_at_null_byte(string) - string.split(NULL_BYTE, 2).first + string.split(NULL_BYTE, 2).first.to_s end def self.split_by_null_byte(string) diff --git a/spec/lib/id3tag/string_util_spec.rb b/spec/lib/id3tag/string_util_spec.rb index af56c97..52ecb6d 100644 --- a/spec/lib/id3tag/string_util_spec.rb +++ b/spec/lib/id3tag/string_util_spec.rb @@ -47,6 +47,21 @@ end end + describe "cut_at_null_byte" do + let(:input) { } + subject { described_class.cut_at_null_byte(input) } + + context 'when content is empty' do + let(:input) { '' } + it { is_expected.to eq('') } + end + + context 'when content is present' do + let(:input) { "a\u0000b" } + it { is_expected.to eq('a') } + end + end + describe "split_by_null_byte" do let(:input) { } subject { described_class.split_by_null_byte(input) }