Skip to content

Commit d39c108

Browse files
committed
Fix handling of :ignore_fields
1 parent f0ea998 commit d39c108

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/csv-diff/csv_diff.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def initialize(left, right, options = {})
8484
@right = right.is_a?(CSVSource) ? right : CSVSource.new(right, options)
8585
raise "No field names found in right (to) source" unless @right.field_names && @right.field_names.size > 0
8686
@warnings = []
87-
@diff_fields = get_diff_fields(@left.field_names, @right.field_names, options.fetch(:ignore_fields, []))
87+
@diff_fields = get_diff_fields(@left.field_names, @right.field_names, options[:ignore_fields])
8888
@key_fields = @left.key_fields.map{ |kf| @diff_fields[kf] }
8989
diff(options)
9090
end
@@ -132,7 +132,8 @@ def get_diff_fields(left_fields, right_fields, ignore_fields)
132132
diff_fields = []
133133
right_fields.each_with_index do |fld, i|
134134
if left_fields.include?(fld)
135-
diff_fields << fld unless ignore_fields.include?(fld) || ignore_fields.include?(i)
135+
diff_fields << fld unless ignore_fields && (ignore_fields.include?(fld) ||
136+
ignore_fields.include?(i))
136137
else
137138
@warnings << "Field '#{fld}' is missing from the left (from) file, and won't be diffed"
138139
end

0 commit comments

Comments
 (0)