From 63e0e17eafb37369decdced0cd691f065d1f1048 Mon Sep 17 00:00:00 2001 From: Gabriel Rios Date: Wed, 16 Mar 2022 10:34:58 -0300 Subject: [PATCH 1/2] Prefix strings starting with '%' and '|' --- lib/csv-safe.rb | 2 +- spec/csv_safe_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/csv-safe.rb b/lib/csv-safe.rb index 391e92f..fecc1d2 100644 --- a/lib/csv-safe.rb +++ b/lib/csv-safe.rb @@ -21,7 +21,7 @@ def <<(row) # TODO: performance test if i'm adding # too many method calls to hot code def starts_with_special_character?(str) - %w[- = + @].include?(str[0]) + %w[- = + @ % |].include?(str[0]) end def prefix(field) diff --git a/spec/csv_safe_spec.rb b/spec/csv_safe_spec.rb index 4594aa8..cf8305d 100644 --- a/spec/csv_safe_spec.rb +++ b/spec/csv_safe_spec.rb @@ -59,6 +59,18 @@ it { should eq expected } end + context 'with a field that starts with a %' do + let(:field) { "%0A-2+3+cmd|' /C calc'!'E2'" } + let(:expected) { "'%0A-2+3+cmd|' /C calc'!'E2'" } + it { should eq expected } + end + + context 'with a field that starts with a %' do + let(:field) { "|-2+3+cmd|' /C calc'!'E2'" } + let(:expected) { "'|-2+3+cmd|' /C calc'!'E2'" } + it { should eq expected } + end + context 'with a field that is a date' do let(:field) { Time.now } it { should eq field } @@ -224,6 +236,17 @@ def arr_to_line(arr) end it { should eq arr_to_line(expected) } end + + context 'because it starts with a %' do + let(:row) do + ["%0A-2+3+cmd|' /C calc'!'E2'"] + end + + let(:expected) do + ["'%0A-2+3+cmd|' /C calc'!'E2'"] + end + it { should eq arr_to_line(expected) } + end end end end From 7538b8b6f572c27c6c8b5b4d0b920102f9790105 Mon Sep 17 00:00:00 2001 From: Gabriel Rios Date: Thu, 17 Mar 2022 09:25:05 -0300 Subject: [PATCH 2/2] Bump version --- csv-safe.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csv-safe.gemspec b/csv-safe.gemspec index 6335547..4fd596d 100644 --- a/csv-safe.gemspec +++ b/csv-safe.gemspec @@ -4,7 +4,7 @@ require 'csv-safe' Gem::Specification.new do |spec| spec.name = 'csv-safe' - spec.version = '2.1.0' + spec.version = '3.0.0' spec.authors = ['Alex Zvorygin'] spec.email = ['grafetu@gmail.com']