diff --git a/CHANGELOG.md b/CHANGELOG.md index a077a88..4f04d94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 4.3.1 + +- Fix bug (since 4.2.0) that caused column names not to be truncated after null character + ## 4.3.0 - Drop support for Ruby versions older than 3.0 diff --git a/lib/dbf/column.rb b/lib/dbf/column.rb index a18b447..b36ce6f 100644 --- a/lib/dbf/column.rb +++ b/lib/dbf/column.rb @@ -78,7 +78,7 @@ def underscored_name private def clean(value) # :nodoc: - value.strip.delete("\x00").gsub(/[^\x20-\x7E]/, '') + value.strip.partition("\x00").first.gsub(/[^\x20-\x7E]/, '') end def encode(value, strip_output: false) # :nodoc: diff --git a/lib/dbf/version.rb b/lib/dbf/version.rb index 14639e2..e6ac5e9 100644 --- a/lib/dbf/version.rb +++ b/lib/dbf/version.rb @@ -1,3 +1,3 @@ module DBF - VERSION = '4.3.0'.freeze + VERSION = '4.3.1'.freeze end diff --git a/spec/dbf/column_spec.rb b/spec/dbf/column_spec.rb index 43311f9..b26bec0 100644 --- a/spec/dbf/column_spec.rb +++ b/spec/dbf/column_spec.rb @@ -287,12 +287,12 @@ describe '#name' do it 'contains only ASCII characters' do column = DBF::Column.new table, "--\x1F-\x68\x65\x6C\x6C\x6F \x00world-\x80--", 'N', 1, 0 - expect(column.name).to eq '---hello world---' + expect(column.name).to eq '---hello ' end it 'is truncated at the null character' do column = DBF::Column.new table, "--\x1F-\x68\x65\x6C\x6C\x6F \x00world-\x80\x80--", 'N', 1, 0 - expect(column.name).to eq '---hello world---' + expect(column.name).to eq '---hello ' end end end