csv 3.2.6 → 3.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48581eef7d2903fa52d36b48a8c1596396a5957b166c99ea8dcfd14ffb0dc221
4
- data.tar.gz: fa6a5cdd9ade30c0a45f7974dcb43128d5e99cc7bf344e9e5b012993ad081ffe
3
+ metadata.gz: c64817c16c8991fc2596875101449b5452326fe91bd05e4bb6a66213113525d6
4
+ data.tar.gz: 19d6d80d6959f6cde0ac651774ea795dbd0f949135cae021fef3983d94248f9c
5
5
  SHA512:
6
- metadata.gz: 00f55443919b4ece138c025818a440ed4a6d0bed64917bcb6f6e810e318f4738f9e129371434c8711173e818b5b58e1d4b2ac2987612617922fda74f03bd3a4b
7
- data.tar.gz: 0b83b3b64bf5287653054fa8ecfd4e345f5c41a2a0daedbdba355c4d034bc85c917cf87bd9ee1ede54475ec4e31caadaee54cc2553d529e9ba5b0bc1d5806ff0
6
+ metadata.gz: 556f6582468d4a3c2994c12c25dba73b8db65e1a10f7306b9b5bc1fa345f47bf7872db1c603ddcd1a0eb359e7857c51a9874be2231dc821730ae62d15604c3b7
7
+ data.tar.gz: 348a25f4c1bb8e4fe0d71dc944e0a26165627803cb2528fc067642827fd3c253bda48aba179d3575950a7244bd4e8edf2eed9a99101952a07256a3f4f9d1e7fe
data/NEWS.md CHANGED
@@ -1,5 +1,63 @@
1
1
  # News
2
2
 
3
+ ## 3.2.8 - 2023-11-08
4
+
5
+ ### Improvements
6
+
7
+ * Added `CSV::InvalidEncodingError`.
8
+
9
+ Patch by Kosuke Shibata.
10
+
11
+ GH-287
12
+
13
+ ### Thanks
14
+
15
+ * Kosuke Shibata
16
+
17
+ ## 3.2.7 - 2023-06-26
18
+
19
+ ### Improvements
20
+
21
+ * Removed an unused internal variable.
22
+ [GH-273](https://github.com/ruby/csv/issues/273)
23
+ [Patch by Mau Magnaguagno]
24
+
25
+ * Changed to use `https://` instead of `http://` in documents.
26
+ [GH-274](https://github.com/ruby/csv/issues/274)
27
+ [Patch by Vivek Bharath Akupatni]
28
+
29
+ * Added prefix to a helper module in test.
30
+ [GH-278](https://github.com/ruby/csv/issues/278)
31
+ [Patch by Luke Gruber]
32
+
33
+ * Added a documentation for `liberal_parsing: {backslash_quotes: true}`.
34
+ [GH-280](https://github.com/ruby/csv/issues/280)
35
+ [Patch by Mark Schneider]
36
+
37
+ ### Fixes
38
+
39
+ * Fixed a wrong execution result in documents.
40
+ [GH-276](https://github.com/ruby/csv/issues/276)
41
+ [Patch by Yuki Tsujimoto]
42
+
43
+ * Fixed a bug that the same line is used multiple times.
44
+ [GH-279](https://github.com/ruby/csv/issues/279)
45
+ [Reported by Gabriel Nagy]
46
+
47
+ ### Thanks
48
+
49
+ * Mau Magnaguagno
50
+
51
+ * Vivek Bharath Akupatni
52
+
53
+ * Yuki Tsujimoto
54
+
55
+ * Luke Gruber
56
+
57
+ * Mark Schneider
58
+
59
+ * Gabriel Nagy
60
+
3
61
  ## 3.2.6 - 2022-12-08
4
62
 
5
63
  ### Improvements
@@ -1,13 +1,13 @@
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
@@ -520,7 +520,7 @@ Apply multiple header converters by defining and registering a custom header con
520
520
  To capture unconverted field values, use option +:unconverted_fields+:
521
521
  source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
522
522
  parsed = CSV.parse(source, converters: :integer, unconverted_fields: true)
523
- parsed # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
523
+ parsed # => [["Name", "Value"], ["foo", 0], ["bar", 1], ["baz", 2]]
524
524
  parsed.each {|row| p row.unconverted_fields }
525
525
  Output:
526
526
  ["Name", "Value"]
data/lib/csv/parser.rb CHANGED
@@ -101,7 +101,7 @@ class CSV
101
101
  position = @scanner.pos
102
102
  offset = 0
103
103
  n_row_separator_chars = row_separator.size
104
- # trace(__method__, :start, line, input)
104
+ # trace(__method__, :start, input)
105
105
  while true
106
106
  input.each_line(row_separator) do |line|
107
107
  @scanner.pos += line.bytesize
@@ -157,6 +157,7 @@ class CSV
157
157
  # trace(__method__, pattern, :done, :last, value) if @last_scanner
158
158
  return value if @last_scanner
159
159
 
160
+ # trace(__method__, pattern, :done, :nil) if value.nil?
160
161
  return nil if value.nil?
161
162
  while @scanner.eos? and read_chunk and (sub_value = @scanner.scan(pattern))
162
163
  # trace(__method__, pattern, :sub, sub_value)
@@ -200,7 +201,8 @@ class CSV
200
201
  # trace(__method__, :rescan, start, buffer)
201
202
  string = @scanner.string
202
203
  if scanner == @scanner
203
- keep = string.byteslice(start, string.bytesize - start)
204
+ keep = string.byteslice(start,
205
+ string.bytesize - @scanner.pos - start)
204
206
  else
205
207
  keep = string
206
208
  end
@@ -412,8 +414,7 @@ class CSV
412
414
  else
413
415
  lineno = @lineno + 1
414
416
  end
415
- message = "Invalid byte sequence in #{@encoding}"
416
- raise MalformedCSVError.new(message, lineno)
417
+ raise InvalidEncodingError.new(@encoding, lineno)
417
418
  rescue UnexpectedError => error
418
419
  if @scanner
419
420
  ignore_broken_line
@@ -485,7 +486,6 @@ class CSV
485
486
  message = ":quote_char has to be nil or a single character String"
486
487
  raise ArgumentError, message
487
488
  end
488
- @double_quote_character = @quote_character * 2
489
489
  @escaped_quote_character = Regexp.escape(@quote_character)
490
490
  @escaped_quote = Regexp.new(@escaped_quote_character)
491
491
  end
@@ -875,8 +875,7 @@ class CSV
875
875
  !line.valid_encoding?
876
876
  end
877
877
  if index
878
- message = "Invalid byte sequence in #{@encoding}"
879
- raise MalformedCSVError.new(message, @lineno + index + 1)
878
+ raise InvalidEncodingError.new(@encoding, @lineno + index + 1)
880
879
  end
881
880
  end
882
881
  Scanner.new(string)
data/lib/csv/row.rb CHANGED
@@ -703,7 +703,7 @@ class CSV
703
703
  # by +index_or_header+ and +specifiers+.
704
704
  #
705
705
  # The nested objects may be instances of various classes.
706
- # See {Dig Methods}[https://docs.ruby-lang.org/en/master/dig_methods_rdoc.html].
706
+ # See {Dig Methods}[rdoc-ref:dig_methods.rdoc].
707
707
  #
708
708
  # Examples:
709
709
  # source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
data/lib/csv/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  class CSV
4
4
  # The version of the installed library.
5
- VERSION = "3.2.6"
5
+ VERSION = "3.2.8"
6
6
  end
data/lib/csv.rb CHANGED
@@ -70,7 +70,7 @@
70
70
  # == What is CSV, really?
71
71
  #
72
72
  # CSV maintains a pretty strict definition of CSV taken directly from
73
- # {the RFC}[http://www.ietf.org/rfc/rfc4180.txt]. I relax the rules in only one
73
+ # {the RFC}[https://www.ietf.org/rfc/rfc4180.txt]. I relax the rules in only one
74
74
  # place and that is to make using this library easier. CSV will parse all valid
75
75
  # CSV.
76
76
  #
@@ -102,14 +102,6 @@ require_relative "csv/writer"
102
102
 
103
103
  # == \CSV
104
104
  #
105
- # === In a Hurry?
106
- #
107
- # If you are familiar with \CSV data and have a particular task in mind,
108
- # you may want to go directly to the:
109
- # - {Recipes for CSV}[doc/csv/recipes/recipes_rdoc.html].
110
- #
111
- # Otherwise, read on here, about the API: classes, methods, and constants.
112
- #
113
105
  # === \CSV Data
114
106
  #
115
107
  # \CSV (comma-separated values) data is a text representation of a table:
@@ -854,6 +846,15 @@ class CSV
854
846
  end
855
847
  end
856
848
 
849
+ # The error thrown when the parser encounters invalid encoding in CSV.
850
+ class InvalidEncodingError < MalformedCSVError
851
+ attr_reader :encoding
852
+ def initialize(encoding, line_number)
853
+ @encoding = encoding
854
+ super("Invalid byte sequence in #{encoding}", line_number)
855
+ end
856
+ end
857
+
857
858
  #
858
859
  # A FieldInfo Struct contains details about a field's position in the data
859
860
  # source it was read from. CSV will pass this Struct to some blocks that make
@@ -1144,7 +1145,7 @@ class CSV
1144
1145
  # File.read('t.csv') # => "Name,Value\nFOO,0\nBAR,-1\nBAZ,-2\n"
1145
1146
  #
1146
1147
  # When neither +in_string_or_io+ nor +out_string_or_io+ given,
1147
- # parses from {ARGF}[https://docs.ruby-lang.org/en/master/ARGF.html]
1148
+ # parses from {ARGF}[rdoc-ref:ARGF]
1148
1149
  # and generates to STDOUT.
1149
1150
  #
1150
1151
  # Without headers:
@@ -1314,8 +1315,8 @@ class CSV
1314
1315
  #
1315
1316
  # Arguments:
1316
1317
  # * Argument +path_or_io+ must be a file path or an \IO stream.
1317
- # * Argument +mode+, if given, must be a \File mode
1318
- # See {Open Mode}[https://ruby-doc.org/core/IO.html#method-c-new-label-Open+Mode].
1318
+ # * Argument +mode+, if given, must be a \File mode.
1319
+ # See {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes].
1319
1320
  # * Arguments <tt>**options</tt> must be keyword options.
1320
1321
  # See {Options for Parsing}[#class-CSV-label-Options+for+Parsing].
1321
1322
  # * This method optionally accepts an additional <tt>:encoding</tt> option
@@ -1521,8 +1522,8 @@ class CSV
1521
1522
  #
1522
1523
  # * Argument +path+, if given, must be the path to a file.
1523
1524
  # :include: ../doc/csv/arguments/io.rdoc
1524
- # * Argument +mode+, if given, must be a \File mode
1525
- # See {Open Mode}[IO.html#method-c-new-label-Open+Mode].
1525
+ # * Argument +mode+, if given, must be a \File mode.
1526
+ # See {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes].
1526
1527
  # * Arguments <tt>**options</tt> must be keyword options.
1527
1528
  # See {Options for Generating}[#class-CSV-label-Options+for+Generating].
1528
1529
  # * This method optionally accepts an additional <tt>:encoding</tt> option
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.6
4
+ version: 3.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Edward Gray II
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-12-08 00:00:00.000000000 Z
12
+ date: 2023-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.4.0.dev
148
+ rubygems_version: 3.5.0.dev
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: CSV Reading and Writing