Module: OpenLoam::Csv

Defined in:
lib/open_loam/csv.rb

Overview

CSV formula-injection defense. A cell whose value starts with =, +, -, @, or a tab/CR is treated as a FORMULA by Excel/Google Sheets when the file is opened — so =cmd|... or =HYPERLINK(...) in imported/exported data can run. Prefixing such a value with a single quote neutralizes it while leaving the visible text intact. Applied on every CSV cell OpenLoam writes (export + the import error file).

Constant Summary collapse

DANGEROUS =
/\A[=+\-@\t\r]/

Class Method Summary collapse

Class Method Details

.safe(value) ⇒ Object



13
14
15
16
# File 'lib/open_loam/csv.rb', line 13

def safe(value)
  string = value.to_s
  string.match?(DANGEROUS) ? "'#{string}" : value
end