Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix starting with '%' #8

Merged
merged 2 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion csv-safe.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
2 changes: 1 addition & 1 deletion lib/csv-safe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions spec/csv_safe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down