csv 3.2.7 → 3.2.9

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: 6cc7b1ce29466412d00abcdb6afe594aa953f4b88367086398a3376484ca3344
4
- data.tar.gz: b8112d963f92496cc775996c4e65d5b585601210fc03a4bc86eb4bf3c20e5f7d
3
+ metadata.gz: d7dabc413b85090aa7c9c93ca318de9adb1c0c2d94273f4e8d23d73d2882680a
4
+ data.tar.gz: 8e8484c342de0947a59af726ab20d7a88a2ae766a9e62139edb6c5650d144d0a
5
5
  SHA512:
6
- metadata.gz: 3c29b38c150c691b52d0be24ab3dcdf32c430f2870de3ae4b26e704368caead83b27a581324a73515a85df8dc9571ab9f5fef1e8aa16a78f2ebfe3981a036063
7
- data.tar.gz: 40cc68cb5a5eae059c3924e21e4fb53ae19e3c129f4b57e2bdcab35798742616daee93cf4bf9998de5333e03b01cc7b08a11da9700f04913a45f80741542d8f5
6
+ metadata.gz: 28edfb536bed667f78a618a3d13f5b305d1749879efae7256aaa8a0fa84694f2df7cc285851976b8b2f45ce9a7ae5741f9bd4277c3ea32c9a27fd2379a0f1be2
7
+ data.tar.gz: 7fe44532cde1e9022da25f798b696ad51b7c81bc3bd64cfd97610d13f073f141886bfdd03e9bb710bab2d3e7fda71a47cfea0ea7da8d3f6c06b38edfc295e364
data/NEWS.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # News
2
2
 
3
+ ## 3.2.9 - 2024-03-22
4
+
5
+ ### Fixes
6
+
7
+ * Fixed a parse bug that wrong result may be happen when:
8
+
9
+ * `:skip_lines` is used
10
+ * `:row_separator` is `"\r\n"`
11
+ * There is a line that includes `\n` as a column value
12
+
13
+ Reported by Ryo Tsukamoto.
14
+
15
+ GH-296
16
+
17
+ ### Thanks
18
+
19
+ * Ryo Tsukamoto
20
+
21
+ ## 3.2.8 - 2023-11-08
22
+
23
+ ### Improvements
24
+
25
+ * Added `CSV::InvalidEncodingError`.
26
+
27
+ Patch by Kosuke Shibata.
28
+
29
+ GH-287
30
+
31
+ ### Thanks
32
+
33
+ * Kosuke Shibata
34
+
3
35
  ## 3.2.7 - 2023-06-26
4
36
 
5
37
  ### Improvements
data/README.md CHANGED
@@ -30,8 +30,8 @@ end
30
30
 
31
31
  ## Documentation
32
32
 
33
- - [API](https://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html): all classes, methods, and constants.
34
- - [Recipes](https://ruby-doc.org/core/doc/csv/recipes/recipes_rdoc.html): specific code for specific tasks.
33
+ - [API](https://ruby.github.io/csv/): all classes, methods, and constants.
34
+ - [Recipes](https://ruby.github.io/csv/doc/csv/recipes/recipes_rdoc.html): specific code for specific tasks.
35
35
 
36
36
  ## Development
37
37
 
data/lib/csv/parser.rb CHANGED
@@ -220,6 +220,15 @@ class CSV
220
220
  end
221
221
  # trace(__method__, :repos, start, buffer)
222
222
  @scanner.pos = start
223
+ last_scanner, last_start, last_buffer = @keeps.last
224
+ # Drop the last buffer when the last buffer is the same data
225
+ # in the last keep. If we keep it, we have duplicated data
226
+ # by the next keep_back.
227
+ if last_scanner == @scanner and
228
+ last_buffer and
229
+ last_buffer == last_scanner.string.byteslice(last_start, start)
230
+ @keeps.last[2] = nil
231
+ end
223
232
  end
224
233
  read_chunk if @scanner.eos?
225
234
  end
@@ -414,8 +423,7 @@ class CSV
414
423
  else
415
424
  lineno = @lineno + 1
416
425
  end
417
- message = "Invalid byte sequence in #{@encoding}"
418
- raise MalformedCSVError.new(message, lineno)
426
+ raise InvalidEncodingError.new(@encoding, lineno)
419
427
  rescue UnexpectedError => error
420
428
  if @scanner
421
429
  ignore_broken_line
@@ -876,8 +884,7 @@ class CSV
876
884
  !line.valid_encoding?
877
885
  end
878
886
  if index
879
- message = "Invalid byte sequence in #{@encoding}"
880
- raise MalformedCSVError.new(message, @lineno + index + 1)
887
+ raise InvalidEncodingError.new(@encoding, @lineno + index + 1)
881
888
  end
882
889
  end
883
890
  Scanner.new(string)
@@ -894,18 +901,15 @@ class CSV
894
901
  def skip_needless_lines
895
902
  return unless @skip_lines
896
903
 
897
- until @scanner.eos?
898
- @scanner.keep_start
899
- line = @scanner.scan_all(@not_line_end) || "".encode(@encoding)
904
+ @scanner.keep_start
905
+ @scanner.each_line(@row_separator) do |line|
900
906
  line << @row_separator if parse_row_end
901
- if skip_line?(line)
902
- @lineno += 1
903
- @scanner.keep_drop
904
- else
905
- @scanner.keep_back
906
- return
907
- end
907
+ break unless skip_line?(line)
908
+ @lineno += 1
909
+ @scanner.keep_drop
910
+ @scanner.keep_start
908
911
  end
912
+ @scanner.keep_back
909
913
  end
910
914
 
911
915
  def skip_line?(line)
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.7"
5
+ VERSION = "3.2.9"
6
6
  end
data/lib/csv.rb CHANGED
@@ -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
@@ -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,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.7
4
+ version: 3.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Edward Gray II
8
8
  - Kouhei Sutou
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2023-06-26 00:00:00.000000000 Z
11
+ date: 2024-03-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
@@ -128,7 +127,6 @@ licenses:
128
127
  - Ruby
129
128
  - BSD-2-Clause
130
129
  metadata: {}
131
- post_install_message:
132
130
  rdoc_options:
133
131
  - "--main"
134
132
  - README.md
@@ -145,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
143
  - !ruby/object:Gem::Version
146
144
  version: '0'
147
145
  requirements: []
148
- rubygems_version: 3.5.0.dev
149
- signing_key:
146
+ rubygems_version: 3.6.0.dev
150
147
  specification_version: 4
151
148
  summary: CSV Reading and Writing
152
149
  test_files: []