Skip to content

Commit 4942dc5

Browse files
authored
Extend spreadsheet_safe prefix guard to '-', '+', and '@'
1 parent 8346200 commit 4942dc5

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.0.10
2+
- Extend `spreadsheet_safe` prefix guard to '-', '+', and '@' [#27](https://github.com/logstash-plugins/logstash-output-csv/pull/27)
3+
14
## 3.0.9
25
- Fix: updates syntax to JRuby 9.4 [#25](https://github.com/logstash-plugins/logstash-output-csv/pull/25)
36

lib/logstash/outputs/csv.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ def get_value(name, event)
6666

6767
private
6868
def escape_csv(val)
69-
(spreadsheet_safe && val.is_a?(String) && val.start_with?("=")) ? "'#{val}" : val
69+
(spreadsheet_safe && val.is_a?(String) && val.start_with?(/[=+\-@]/)) ? "'#{val}" : val
7070
end
7171
end # class LogStash::Outputs::CSV

logstash-output-csv.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-output-csv'
4-
s.version = '3.0.9'
4+
s.version = '3.0.10'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Writes events to disk in a delimited format"
77
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

spec/outputs/csv_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,24 @@
139139
let(:event_data) do
140140
{
141141
"f1" => "1+1",
142-
"f2" => "=1+1"
142+
"f2" => "=1+1",
143+
"f3" => "+1+1",
144+
"f4" => "-1+1",
145+
"f5" => "@1+1"
143146
}
144147
end
145148
let(:events) do
146149
[ LogStash::Event.new(event_data) ]
147150
end
148151

149-
let(:options) { { "path" => tmpfile, "fields" => ["f1", "f2"] } }
152+
let(:options) { { "path" => tmpfile, "fields" => ["f1", "f2", "f3", "f4", "f5"] } }
150153
it "escapes them correctly" do
151154
expect(csv_output.size).to eq(1)
152155
expect(csv_output[0][0]).to eq("1+1")
153156
expect(csv_output[0][1]).to eq("'=1+1")
157+
expect(csv_output[0][2]).to eq("'+1+1")
158+
expect(csv_output[0][3]).to eq("'-1+1")
159+
expect(csv_output[0][4]).to eq("'@1+1")
154160
end
155161

156162
context "when escaping is turned off" do

0 commit comments

Comments
 (0)