Defect #7039 » csv_text_fields_eol.patch
lib/faster_csv.rb (working copy) | ||
---|---|---|
1755 | 1755 |
|
1756 | 1756 |
# establish quoting rules |
1757 | 1757 |
do_quote = lambda do |field| |
1758 |
@quote_char +
|
|
1759 |
String(field).gsub(@quote_char, @quote_char * 2) +
|
|
1758 |
@quote_char +
|
|
1759 |
stringify_field(field).gsub(@quote_char, @quote_char * 2) +
|
|
1760 | 1760 |
@quote_char |
1761 | 1761 |
end |
1762 | 1762 |
@quote = if options.delete(:force_quotes) |
... | ... | |
1766 | 1766 |
if field.nil? # represent +nil+ fields as empty unquoted fields |
1767 | 1767 |
"" |
1768 | 1768 |
else |
1769 |
field = String(field) # Stringify fields
|
|
1769 |
field = stringify_field(field)
|
|
1770 | 1770 |
# represent empty fields as empty quoted fields |
1771 | 1771 |
if field.empty? or |
1772 | 1772 |
field.count("\r\n#{@col_sep}#{@quote_char}").nonzero? |
... | ... | |
1778 | 1778 |
end |
1779 | 1779 |
end |
1780 | 1780 |
end |
1781 |
|
|
1781 |
|
|
1782 |
# Stringify fields |
|
1783 |
def stringify_field(field) |
|
1784 |
if field.is_a?(String) |
|
1785 |
field.gsub("\r\n", "\n") |
|
1786 |
else |
|
1787 |
String(field) |
|
1788 |
end |
|
1789 |
end |
|
1790 |
|
|
1782 | 1791 |
# Pre-compiles parsers and stores them by name for access during reads. |
1783 | 1792 |
def init_parsers(options) |
1784 | 1793 |
# store the parser behaviors |