diff options
author | Mark Schneider <[email protected]> | 2023-05-30 22:30:59 -0400 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2023-06-28 16:37:08 +0900 |
commit | 2098093fb478d766315cabcbf42e64d1fcf4abcc (patch) | |
tree | bcb2b4f06d607017cbf8d32bd4b83303f38ec0af /doc/csv | |
parent | f1313caec1ec465836a20862f97b89e0865f9054 (diff) |
[ruby/csv] docs: Add entry for backslash_quotes liberal parsing
(https://github.com/ruby/csv/pull/280)
https://github.com/ruby/csv/commit/0dcfcd9c48
Diffstat (limited to 'doc/csv')
-rw-r--r-- | doc/csv/options/parsing/liberal_parsing.rdoc | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/doc/csv/options/parsing/liberal_parsing.rdoc b/doc/csv/options/parsing/liberal_parsing.rdoc index b8b9b00c98..603de28613 100644 --- a/doc/csv/options/parsing/liberal_parsing.rdoc +++ b/doc/csv/options/parsing/liberal_parsing.rdoc @@ -1,13 +1,13 @@ ====== Option +liberal_parsing+ -Specifies the boolean value that determines whether +Specifies the boolean or hash value that determines whether CSV will attempt to parse input not conformant with RFC 4180, such as double quotes in unquoted fields. Default value: CSV::DEFAULT_OPTIONS.fetch(:liberal_parsing) # => false -For examples in this section: +For the next two examples: str = 'is,this "three, or four",fields' Without +liberal_parsing+: @@ -17,3 +17,22 @@ Without +liberal_parsing+: With +liberal_parsing+: ary = CSV.parse_line(str, liberal_parsing: true) ary # => ["is", "this \"three", " or four\"", "fields"] + +Use the +backslash_quote+ sub-option to parse values that use +a backslash to escape a double-quote character. This +causes the parser to treat <code>\"</code> as if it were +<code>""</code>. + +For the next two examples: + str = 'Show,"Harry \"Handcuff\" Houdini, the one and only","Tampa Theater"' + +With +liberal_parsing+, but without the +backslash_quote+ sub-option: + # Incorrect interpretation of backslash; incorrectly interprets the quoted comma as a field separator. + ary = CSV.parse_line(str, liberal_parsing: true) + ary # => ["Show", "\"Harry \\\"Handcuff\\\" Houdini", " the one and only\"", "Tampa Theater"] + puts ary[1] # => "Harry \"Handcuff\" Houdini + +With +liberal_parsing+ and its +backslash_quote+ sub-option: + ary = CSV.parse_line(str, liberal_parsing: { backslash_quote: true }) + ary # => ["Show", "Harry \"Handcuff\" Houdini, the one and only", "Tampa Theater"] + puts ary[1] # => Harry "Handcuff" Houdini, the one and only |