From 51ebf89a8ca0c37f55674b0e6b4ac1ee0d12567f Mon Sep 17 00:00:00 2001 From: alex quiterio Date: Tue, 12 Jun 2018 18:23:24 +0200 Subject: [PATCH] Always return a string for `StringUtil#cut_at_null_byte` --- lib/id3tag/string_util.rb | 2 +- spec/lib/id3tag/string_util_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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) }