1
1
====== Option +liberal_parsing+
2
2
3
- Specifies the boolean value that determines whether
3
+ Specifies the boolean or hash value that determines whether
4
4
CSV will attempt to parse input not conformant with RFC 4180,
5
5
such as double quotes in unquoted fields.
6
6
7
7
Default value:
8
8
CSV::DEFAULT_OPTIONS.fetch(:liberal_parsing) # => false
9
9
10
- For examples in this section :
10
+ For the next two examples :
11
11
str = 'is,this "three, or four",fields'
12
12
13
13
Without +liberal_parsing+:
@@ -17,3 +17,22 @@ Without +liberal_parsing+:
17
17
With +liberal_parsing+:
18
18
ary = CSV.parse_line(str, liberal_parsing: true)
19
19
ary # => ["is", "this \"three", " or four\"", "fields"]
20
+
21
+ Use the +backslash_quote+ sub-option to parse values that use
22
+ a backslash to escape a double-quote character. This
23
+ causes the parser to treat <code>\"</code> as if it were
24
+ <code>""</code>.
25
+
26
+ For the next two examples:
27
+ str = 'Show,"Harry \"Handcuff\" Houdini, the one and only","Tampa Theater"'
28
+
29
+ With +liberal_parsing+, but without the +backslash_quote+ sub-option:
30
+ # Incorrect interpretation of backslash; incorrectly interprets the quoted comma as a field separator.
31
+ ary = CSV.parse_line(str, liberal_parsing: true)
32
+ ary # => ["Show", "\"Harry \\\"Handcuff\\\" Houdini", " the one and only\"", "Tampa Theater"]
33
+ puts ary[1] # => "Harry \"Handcuff\" Houdini
34
+
35
+ With +liberal_parsing+ and its +backslash_quote+ sub-option:
36
+ ary = CSV.parse_line(str, liberal_parsing: { backslash_quote: true })
37
+ ary # => ["Show", "Harry \"Handcuff\" Houdini, the one and only", "Tampa Theater"]
38
+ puts ary[1] # => Harry "Handcuff" Houdini, the one and only
0 commit comments