Skip to content

Commit

Permalink
Merge pull request #19 from alex-quiterio/fix-nil-case
Browse files Browse the repository at this point in the history
Always return a string for `StringUtil#cut_at_null_byte`
  • Loading branch information
krists authored Jun 13, 2018
2 parents 6bd7137 + 51ebf89 commit 9910092
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/id3tag/string_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/id3tag/string_util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 9910092

Please sign in to comment.