Commit graph

166 commits

Author SHA1 Message Date
Burdette Lamar
798083fac8
[ruby/csv] [DOC] Fix broken links
(https://github.com/ruby/csv/pull/283)

af64a15b2f
2023-10-03 16:13:18 +09:00
Kosuke Shibata
2325e1cd81
[ruby/csv] Add CSV::InvalidEncodingError
(https://github.com/ruby/csv/pull/287)

To handle encoding errors in CSV parsing with the appropriate error
class

68b44887e5
2023-10-03 16:13:18 +09:00
Sutou Kouhei
88876f02c1 [ruby/csv] All Enumerable based methods consume the same lines with other methods
This may have a performance penalty. We should benchmark this.

GitHub: fix https://github.com/ruby/csv/pull/260

Reported by Lhoussaine Ghallou. Thanks!!!

acc05116c5
2023-05-25 01:44:17 +09:00
Sutou Kouhei
73c56e06c4 [ruby/csv] CSV#read consumes the same lines with other methods like CSV#shift
GitHub: fix https://github.com/ruby/csv/pull/258

Reported by Lhoussaine Ghallou. Thanks!!!

71e6d24e28
2023-05-25 01:44:17 +09:00
Vivek Bharath Akupatni
2ac1efc0f3 [ruby/csv] Use https links instead of http
(https://github.com/ruby/csv/pull/274)

e2a06929a8
2023-02-21 19:31:29 +09:00
Hiroshi SHIBATA
643918ecfe Merge csv-3.2.6 2022-12-09 16:36:22 +09:00
adamroyjones
c70dc3cafb [ruby/csv] Add handling for ambiguous parsing options (https://github.com/ruby/csv/pull/226)
GitHub: fix GH-225

With Ruby 3.0.2 and csv 3.2.1, the file

```ruby
require "csv"
File.open("example.tsv", "w") { |f| f.puts("foo\t\tbar") }
CSV.read("example.tsv", col_sep: "\t", strip: true)
```

produces the error

```
lib/csv/parser.rb:935:in `parse_quotable_robust': TODO: Meaningful
message in line 1. (CSV::MalformedCSVError)
```

However, the CSV in this example is not malformed; instead, ambiguous
options were provided to the parser. It is not obvious (to me) whether
the string should be parsed as

- `["foo\t\tbar"]`,
- `["foo", "bar"]`,
- `["foo", "", "bar"]`, or
- `["foo", nil, "bar"]`.

This commit adds code that raises an exception when this situation is
encountered. Specifically, it checks if the column separator either ends
with or starts with the characters that would be stripped away.

This commit also adds unit tests and updates the documentation.

cc317dd42d
2021-12-24 14:35:33 +09:00
rm155
ee948fc1b4 [ruby/csv] Add support for Ractor (https://github.com/ruby/csv/pull/218)
a802690e11
2021-10-24 05:57:33 +09:00
Anthony Hernandez
8fde54a3b5 [ruby/csv] CSV(): Add support for Ruby 3 (https://github.com/ruby/csv/pull/215)
The implementation of the `CSV` shortcut method is broken in Ruby 3
for calls that look like this:

```ruby
CSV(write_stream, col_sep: "|", headers: headers, write_headers: true) do |csv|
  ...
end
```

The above will result in the following error when the `CSV` method attempts to pass
on arguments to `CSV#instance`:

```
ArgumentError: wrong number of arguments (given 2, expected 0..1)
```

The issue is due to the changes in Ruby 3 relating to positional & keyword arguments.

This commit updates the `CSV()` shortcut implementation to work with Ruby 3, and also
updates the documentation for the shortcut method.

310dee45fa
2021-10-24 05:57:33 +09:00
Sutou Kouhei
8ba98f83b0 [ruby/csv] Use "\n" for the default row separator on Ruby 3.0 or later
1f9cbc170e
2021-10-24 05:57:33 +09:00
Sutou Kouhei
39ecdabe67 [ruby/csv] Resolve CSV::Converters and HeaderConverters lazy
It's for Ractor. If you want to use the built-in converters, you
should call Ractor.make_shareable(CSV::Converters) and/or
Ractor.make_shareable(CSV::HeaderConverters).

b0b1325d6b
2021-10-24 05:57:33 +09:00
Vince
8aaa1c279f [ruby/csv] doc: Match text to the struct name (https://github.com/ruby/csv/pull/217)
744e41130c
2021-10-24 05:57:33 +09:00
Kenta Murata
441cd156e0 [ruby/csv] Fix typo [ci skip]
117bcf311e
2020-12-27 15:27:46 +09:00
Burdette Lamar
5a0c8068c8 [ruby/csv] Clarify and correct RDoc for converters (#178)
f3e9586b34
2020-11-24 09:33:55 +09:00
Burdette Lamar
614afb1647 [ruby/csv] Fix CSV.filter to preserve headers (#174)
Co-authored-by: Sutou Kouhei <kou@clear-code.com>

203c5e0574
2020-11-24 09:33:55 +09:00
Burdette Lamar
d2913f912f [ruby/csv] Add link to Wikipedia article Table (#167)
fe975c41d2
2020-11-24 09:33:55 +09:00
Sutou Kouhei
c6f389d84e [ruby/csv] Move doc/* to doc/csv/* to work in ruby/ruby too
910f8e0c5d
2020-07-21 09:17:54 +09:00
Burdette Lamar
935d0b3d05 [ruby/csv] Enhanced RDoc for several methods (#158)
* Enhanced RDoc for several methods

* Update lib/csv.rb

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
72e8b00e51
2020-07-20 15:39:31 +09:00
Sutou Kouhei
4fcfa85cb6
[ruby/csv] CSV.generate_line: use the encoding of the first non ASCII field as the expected encoding
See also: https://github.com/ruby/stringio/issues/13#issuecomment-660543554

004cf49d18
2020-07-20 02:32:55 +09:00
Burdette Lamar
d9749b4715
[ruby/csv] RDoc for converters (#157)
* More on RDoc for converters

* More on RDoc for converters

* Fix indent

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
6044976160
2020-07-20 02:32:54 +09:00
Burdette Lamar
d7c42df0b1
[ruby/csv] Adding call-seq to methods RDoc (#155)
* Adding call-seq to methods RDoc

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>


dbd860c1cd
2020-07-20 02:32:54 +09:00
Burdette Lamar
544d82f49b
[ruby/csv] RDoc: summary lists for options (#154)
* RDoc: summary lists for options

* Enhanced RDoc for certain attributes and instance methods

* Enhanced RDoc for certain attributes and instance methods

* Enhanced RDoc for certain attributes and instance methods

* Enhanced RDoc for certain attributes and instance methods
72d8a25dc9
2020-07-20 02:32:54 +09:00
Burdette Lamar
40c5023629
[ruby/csv] RDoc remark about instance methods (#152)
76379bbe62
2020-07-20 02:32:54 +09:00
Burdette Lamar
a0bee2bbd6
[ruby/csv] Revised introductory RDoc (#151)
60f6f1c28f
2020-07-20 02:32:54 +09:00
Burdette Lamar
da83401ba4
[ruby/csv] Enhanced RDoc for filter (#149)
* Enhanced RDoc for filter

* Correct return values for ::filter, ::foreach, ::parse

* Enhanced RDoc for filter

* Remove "returns nil"s

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2c347f9a3d
2020-07-20 02:32:54 +09:00
Burdette Lamar
66b5cedc29
[ruby/csv] Enhancements for RDoc (#148)
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
25dd4cddbb
2020-07-20 02:32:53 +09:00
Burdette Lamar
d9eff306f5
[ruby/csv] Organize files in doc/ (#145)
bc9ea859b0
2020-07-20 02:32:53 +09:00
Burdette Lamar
920a16893a
[ruby/csv] RDoc for parse_line (adds headers examples) (#143)
* RDoc for parse_line (adds headers examples)

* RDoc for parse_line (adds headers examples)
a161be928e
2020-07-20 02:32:53 +09:00
Burdette Lamar
6106b7badd
[ruby/csv] Added headers to RDoc for CSV.foreach (#142)
* Added headers: to RDoc for CSV.foreach

* Correct options remark for CSV.generate

* Improve citation for option headers
b01945ec3a
2020-07-20 02:32:53 +09:00
Burdette Lamar
e4742fec64
[ruby/csv] Add headers cases to CSV.parse (#141)
* Add headers cases to CSV.parse

* Adjust call-seq for CSV.parse

* Update csv.rb
848c760c43
2020-07-20 02:32:53 +09:00
Burdette Lamar
013cca1f9a
[ruby/csv] doc: fix return value of open {} and use File.open {} (#139)
* Enhanced RDoc for CSV

* Repair example code for foreach
16b425eb37
2020-07-20 02:32:52 +09:00
Burdette Lamar
7c55c96147
[ruby/csv] Rdoc (#137)
Enhancements for open, parse, minor tweaks.
35392f4e45
2020-07-20 02:32:52 +09:00
Burdette Lamar
f89186aebb
[ruby/csv] Add document for CSV.instance (#136)
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
85e293c1ba
2020-07-20 02:32:52 +09:00
Burdette Lamar
1ac702cd29
[ruby/csv] Add RDoc links for delegated methods (#135)
1a4b96b418
2020-07-20 02:32:52 +09:00
Koichi ITO
08e70126ae
[ruby/csv] Add invalid: :replace for CSV.open (#130)
This PR adds `invalid: :replace` for `CSV.open`. It is a PR similar to #129.
5bf687341c
2020-07-20 02:32:52 +09:00
Koichi ITO
4e33a87879
[ruby/csv] Add undef: :replace for CSV.open (#129)
This PR adds `undef: :replace` option for `CSV.open`.

`File.open` has `undef: :replace` option, but `CSV.open` does not.
It would be convenient if `CSV.open` could have a shortcut by having
`undef: :replace` option.
cff8b18480
2020-07-20 02:32:51 +09:00
Burdette Lamar
cf8157e001
[ruby/csv] RDoc for foreach, generate (#127)
* Rdoc for foreach

* Enhanced Rdoc for CSV.generate
8c26c0ab1f
2020-07-20 02:32:51 +09:00
Burdette Lamar
9e6d54a501
[ruby/csv] Enhanced Rdoc (#124)
* Enhanced Rdoc for ::new

* Rdoc for parse_line

* More on parse_line

* Make ::new neater with :call-seq:

* Make better use of :call-seq:

* Rdoc for generate_line

* Respond to review
0d42df39cb
2020-07-20 02:32:51 +09:00
Sutou Kouhei
1822b19221
[ruby/csv] Don't drop stack trace in CSV.parse_line
GitHub: fix GH-120

Reported by Kyle d'Oliveira. Thanks!!!

2959483f90
2020-07-20 02:32:50 +09:00
Burdette Lamar
6ba1abd40c
[ruby/csv] Enhanced Rdoc for CSV (#122)
cd670595d5
2020-07-20 02:32:50 +09:00
TOMITA Masahiro
aeac7db823
[ruby/csv] Fix docs for :strip option (#114)
fb10925271
2020-07-20 02:32:49 +09:00
Seiei Miyagi
3c5b67e0db
[ruby/csv] Ensuring StringIO's encoding in CSV.generate (#111)
dbf55ef008
2020-07-20 02:32:49 +09:00
Sutou Kouhei
92df7d98b6
Import CSV 3.1.2 (#2547) 2019-10-12 14:03:21 +09:00
Jeremy Evans
80b5a0ff2a
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.

This makes the following changes to : handling.

* Treats as **kw, prompting keyword argument separation warnings
  if called with a positional hash.

* Do not look for an option hash if empty keywords are provided.
  For backwards compatibility, treat an empty keyword splat as a empty
  mandatory positional hash argument, but emit a a warning, as this
  behavior will be removed in Ruby 3.  The argument number check
  needs to be moved lower so it can correctly handle an empty
  positional argument being added.

* If the last argument is nil and it is necessary to treat it as an option
  hash in order to make sure all arguments are processed, continue to
  treat the last argument as the option hash. Emit a warning in this case,
  as this behavior will be removed in Ruby 3.

* If splitting the keyword hash into two hashes, issue a warning, as we
  will not be splitting hashes in Ruby 3.

* If the keyword argument is required to fill a mandatory positional
  argument, continue to do so, but emit a warning as this behavior will
  be going away in Ruby 3.

* If keyword arguments are provided and the last argument is not a hash,
  that indicates something wrong. This can happen if a cfunc is calling
  rb_scan_args multiple times, and providing arguments that were not
  passed to it from Ruby.  Callers need to switch to the new
  rb_scan_args_kw function, which allows passing of whether keywords
  were provided.

This commit fixes all warnings caused by the changes above.

It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used.  If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.

In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby.  The last argument may or may not be a hash,
so we can't set keyword argument mode.  However, if it is a
hash, we don't want to warn when treating it as keywords.

In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args.  Also, make
sure not to pass nil in place of an option hash.

Work around Kernel#warn warnings due to problems in the Rubygems
override of the method.  There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.

Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 11:18:49 -07:00
Jeremy Evans
d08e1004e0 Fix keyword argument separation issues in lib
Mostly requires adding ** in either calls or method definitions.
2019-08-30 12:39:31 -07:00
Kazuhiro NISHIYAMA
ffab84fa3e
Fix a typo [ci skip] 2019-08-13 15:27:46 +09:00
Kazuhiro NISHIYAMA
d8e90f5558
Fix a typo in inspect 2019-07-25 16:39:28 +09:00
kawa_tech
8c0edbd79d [ruby/csv] add options doc :quote_empty (#89)
5ca8d79f60
2019-07-14 23:07:31 +09:00
Masafumi Koba
75620c804e [ruby/csv] Add options doc: :write_converters, :write_nil_value, :write_empty_value (#87)
5923ee08b7
2019-07-14 23:07:31 +09:00
hayashiyoshino
fe40841bfb [ruby/csv] add document of strip (#88)
* add document of strip

* modify typo

de0257dc31
2019-07-14 23:07:31 +09:00