csv 3.2.1 → 3.2.2

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: 6aee33c500a979f9f1a9afdbc394545932700ca3442c1b4326b417e59b654ef4
4
- data.tar.gz: 6622e0c4f190f10aa6d3a49b023a6c24540b1133da4d0ef91c07016ba224073f
3
+ metadata.gz: 8682072d16c079d3d25b3f22ca9f06cae36210998194ae3f3de627c74c062453
4
+ data.tar.gz: 755bddbed0b08dd681939a76c5f6a80f2c536a0e72edcf6e8c770be860e5fcae
5
5
  SHA512:
6
- metadata.gz: 7ba35310fd8dc9ffd4075ca31d786b7458fefefaee4c5a00fc326063fb13d020d1959d9970dcf17c222dd5d2422e3d20b9ddcd503caf5a4aad04e0b93159ff60
7
- data.tar.gz: 9d1971baae109ad7396124cfa6bda15bc6db635ff09c6166a750dc22633b552679e5d589b15a57724f7b4aef3ae33c2ccd2fcfcfb1084e71df7f3734347e9926
6
+ metadata.gz: 28e191df9cb41c6ca04a9969eace28deac9217de9f2677b7edec8803531c28b4c47e4866d00fd6edbc5ea0b21f10a4f59b376473475a8c96317949b84b53f49a
7
+ data.tar.gz: 4c747ddbdb78e4e6e8dc725199b2f35aea7949b7eb5b49929c2e818d15cbebfaa07825f57a5ee092a5da7f5c75fc2ea3c035ff204f1a95a12283cea85720e31c
data/NEWS.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # News
2
2
 
3
+ ## 3.2.2 - 2021-12-24
4
+
5
+ ### Improvements
6
+
7
+ * Added a validation for invalid option combination.
8
+ [GitHub#225][Patch by adamroyjones]
9
+
10
+ * Improved documentation for developers.
11
+ [GitHub#227][Patch by Eriko Sugiyama]
12
+
13
+ ### Fixes
14
+
15
+ * Fixed a bug that all of `ARGF` contents may not be consumed.
16
+ [GitHub#228][Reported by Rafael Navaza]
17
+
18
+ * Fixed a bug that some texts may be dropped unexpectedly.
19
+ [Bug #18245][ruby-core:105587][Reported by Hassan Abdul Rehman]
20
+
21
+ ### Thanks
22
+
23
+ * adamroyjones
24
+
25
+ * Eriko Sugiyama
26
+
27
+ * Rafael Navaza
28
+
29
+ * Hassan Abdul Rehman
30
+
3
31
  ## 3.2.1 - 2021-10-23
4
32
 
5
33
  ### Improvements
data/README.md CHANGED
@@ -35,7 +35,7 @@ end
35
35
 
36
36
  ## Development
37
37
 
38
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ After checking out the repo, run `ruby run-test.rb` to check if your changes can pass the test.
39
39
 
40
40
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
41
 
data/lib/csv/parser.rb CHANGED
@@ -85,9 +85,10 @@ class CSV
85
85
  # If there is no more data (eos? = true), it returns "".
86
86
  #
87
87
  class InputsScanner
88
- def initialize(inputs, encoding, chunk_size: 8192)
88
+ def initialize(inputs, encoding, row_separator, chunk_size: 8192)
89
89
  @inputs = inputs.dup
90
90
  @encoding = encoding
91
+ @row_separator = row_separator
91
92
  @chunk_size = chunk_size
92
93
  @last_scanner = @inputs.empty?
93
94
  @keeps = []
@@ -233,7 +234,7 @@ class CSV
233
234
  @last_scanner = @inputs.empty?
234
235
  true
235
236
  else
236
- chunk = input.gets(nil, @chunk_size)
237
+ chunk = input.gets(@row_separator, @chunk_size)
237
238
  if chunk
238
239
  raise InvalidEncoding unless chunk.valid_encoding?
239
240
  @scanner = StringScanner.new(chunk)
@@ -361,6 +362,7 @@ class CSV
361
362
  prepare_skip_lines
362
363
  prepare_strip
363
364
  prepare_separators
365
+ validate_strip_and_col_sep_options
364
366
  prepare_quoted
365
367
  prepare_unquoted
366
368
  prepare_line
@@ -531,6 +533,28 @@ class CSV
531
533
  @not_line_end = Regexp.new("[^\r\n]+".encode(@encoding))
532
534
  end
533
535
 
536
+ # This method verifies that there are no (obvious) ambiguities with the
537
+ # provided +col_sep+ and +strip+ parsing options. For example, if +col_sep+
538
+ # and +strip+ were both equal to +\t+, then there would be no clear way to
539
+ # parse the input.
540
+ def validate_strip_and_col_sep_options
541
+ return unless @strip
542
+
543
+ if @strip.is_a?(String)
544
+ if @column_separator.start_with?(@strip) || @column_separator.end_with?(@strip)
545
+ raise ArgumentError,
546
+ "The provided strip (#{@escaped_strip}) and " \
547
+ "col_sep (#{@escaped_column_separator}) options are incompatible."
548
+ end
549
+ else
550
+ if Regexp.new("\\A[#{@escaped_strip}]|[#{@escaped_strip}]\\z").match?(@column_separator)
551
+ raise ArgumentError,
552
+ "The provided strip (true) and " \
553
+ "col_sep (#{@escaped_column_separator}) options are incompatible."
554
+ end
555
+ end
556
+ end
557
+
534
558
  def prepare_quoted
535
559
  if @quote_character
536
560
  @quotes = Regexp.new(@escaped_quote_character +
@@ -738,6 +762,7 @@ class CSV
738
762
  end
739
763
  InputsScanner.new(inputs,
740
764
  @encoding,
765
+ @row_separator,
741
766
  chunk_size: SCANNER_TEST_CHUNK_SIZE)
742
767
  end
743
768
  else
@@ -745,7 +770,10 @@ class CSV
745
770
  string = nil
746
771
  if @samples.empty? and @input.is_a?(StringIO)
747
772
  string = @input.read
748
- elsif @samples.size == 1 and @input.respond_to?(:eof?) and @input.eof?
773
+ elsif @samples.size == 1 and
774
+ @input != ARGF and
775
+ @input.respond_to?(:eof?) and
776
+ @input.eof?
749
777
  string = @samples[0]
750
778
  end
751
779
  if string
@@ -764,7 +792,7 @@ class CSV
764
792
  StringIO.new(sample)
765
793
  end
766
794
  inputs << @input
767
- InputsScanner.new(inputs, @encoding)
795
+ InputsScanner.new(inputs, @encoding, @row_separator)
768
796
  end
769
797
  end
770
798
  end
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.1"
5
+ VERSION = "3.2.2"
6
6
  end
data/lib/csv.rb CHANGED
@@ -341,6 +341,7 @@ using CSV::MatchP if CSV.const_defined?(:MatchP)
341
341
  # liberal_parsing: false,
342
342
  # nil_value: nil,
343
343
  # empty_value: "",
344
+ # strip: false,
344
345
  # # For generating.
345
346
  # write_headers: nil,
346
347
  # quote_empty: true,
@@ -348,7 +349,6 @@ using CSV::MatchP if CSV.const_defined?(:MatchP)
348
349
  # write_converters: nil,
349
350
  # write_nil_value: nil,
350
351
  # write_empty_value: "",
351
- # strip: false,
352
352
  # }
353
353
  #
354
354
  # ==== Options for Parsing
@@ -366,8 +366,9 @@ using CSV::MatchP if CSV.const_defined?(:MatchP)
366
366
  # - +header_converters+: Specifies the header converters to be used.
367
367
  # - +skip_blanks+: Specifies whether blanks lines are to be ignored.
368
368
  # - +skip_lines+: Specifies how comments lines are to be recognized.
369
- # - +strip+: Specifies whether leading and trailing whitespace are
370
- # to be stripped from fields..
369
+ # - +strip+: Specifies whether leading and trailing whitespace are to be
370
+ # stripped from fields. This must be compatible with +col_sep+; if it is not,
371
+ # then an +ArgumentError+ exception will be raised.
371
372
  # - +liberal_parsing+: Specifies whether \CSV should attempt to parse
372
373
  # non-compliant data.
373
374
  # - +nil_value+: Specifies the object that is to be substituted for each null (no-text) field.
@@ -946,6 +947,7 @@ class CSV
946
947
  liberal_parsing: false,
947
948
  nil_value: nil,
948
949
  empty_value: "",
950
+ strip: false,
949
951
  # For generating.
950
952
  write_headers: nil,
951
953
  quote_empty: true,
@@ -953,7 +955,6 @@ class CSV
953
955
  write_converters: nil,
954
956
  write_nil_value: nil,
955
957
  write_empty_value: "",
956
- strip: false,
957
958
  }.freeze
958
959
 
959
960
  class << self
@@ -1879,11 +1880,11 @@ class CSV
1879
1880
  encoding: nil,
1880
1881
  nil_value: nil,
1881
1882
  empty_value: "",
1883
+ strip: false,
1882
1884
  quote_empty: true,
1883
1885
  write_converters: nil,
1884
1886
  write_nil_value: nil,
1885
- write_empty_value: "",
1886
- strip: false)
1887
+ write_empty_value: "")
1887
1888
  raise ArgumentError.new("Cannot parse nil as CSV") if data.nil?
1888
1889
 
1889
1890
  if data.is_a?(String)
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.1
4
+ version: 3.2.2
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: 2021-10-22 00:00:00.000000000 Z
12
+ date: 2021-12-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
149
  requirements: []
150
- rubygems_version: 3.3.0.dev
150
+ rubygems_version: 3.3.0
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: CSV Reading and Writing