summaryrefslogtreecommitdiff
path: root/lib/csv.rb
Commit message (Collapse)AuthorAgeFilesLines
* [ruby/csv] Add handling for ambiguous parsing options ↵adamroyjones2021-12-241-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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. https://github.com/ruby/csv/commit/cc317dd42d
* [ruby/csv] Add support for Ractor (https://github.com/ruby/csv/pull/218)rm1552021-10-241-0/+21
| | | | https://github.com/ruby/csv/commit/a802690e11
* [ruby/csv] CSV(): Add support for Ruby 3 (https://github.com/ruby/csv/pull/215)Anthony Hernandez2021-10-241-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | 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. https://github.com/ruby/csv/commit/310dee45fa
* [ruby/csv] Use "\n" for the default row separator on Ruby 3.0 or laterSutou Kouhei2021-10-241-5/+5
| | | | https://github.com/ruby/csv/commit/1f9cbc170e
* [ruby/csv] Resolve CSV::Converters and HeaderConverters lazySutou Kouhei2021-10-241-2/+2
| | | | | | | | 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). https://github.com/ruby/csv/commit/b0b1325d6b
* [ruby/csv] doc: Match text to the struct name ↵Vince2021-10-241-1/+1
| | | | | | (https://github.com/ruby/csv/pull/217) https://github.com/ruby/csv/commit/744e41130c
* [ruby/csv] Fix typo [ci skip]Kenta Murata2020-12-271-1/+1
| | | | https://github.com/ruby/csv/commit/117bcf311e
* [ruby/csv] Clarify and correct RDoc for converters (#178)Burdette Lamar2020-11-241-25/+31
| | | | https://github.com/ruby/csv/commit/f3e9586b34
* [ruby/csv] Fix CSV.filter to preserve headers (#174)Burdette Lamar2020-11-241-1/+20
| | | | | | Co-authored-by: Sutou Kouhei <kou@clear-code.com> https://github.com/ruby/csv/commit/203c5e0574
* [ruby/csv] Add link to Wikipedia article Table (#167)Burdette Lamar2020-11-241-0/+5
| | | | https://github.com/ruby/csv/commit/fe975c41d2
* [ruby/csv] Move doc/* to doc/csv/* to work in ruby/ruby tooSutou Kouhei2020-07-211-29/+29
| | | | https://github.com/ruby/csv/commit/910f8e0c5d
* [ruby/csv] Enhanced RDoc for several methods (#158)Burdette Lamar2020-07-201-16/+112
| | | | | | | | | | | * 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> https://github.com/ruby/csv/commit/72e8b00e51
* [ruby/csv] CSV.generate_line: use the encoding of the first non ASCII field ↵Sutou Kouhei2020-07-201-2/+14
| | | | | | | | as the expected encoding See also: https://github.com/ruby/stringio/issues/13#issuecomment-660543554 https://github.com/ruby/csv/commit/004cf49d18
* [ruby/csv] RDoc for converters (#157)Burdette Lamar2020-07-201-186/+431
| | | | | | | | | | | * More on RDoc for converters * More on RDoc for converters * Fix indent Co-authored-by: Sutou Kouhei <kou@cozmixng.org> https://github.com/ruby/csv/commit/6044976160
* [ruby/csv] Adding call-seq to methods RDoc (#155)Burdette Lamar2020-07-201-0/+51
| | | | | | | | | * Adding call-seq to methods RDoc Co-authored-by: Sutou Kouhei <kou@cozmixng.org> https://github.com/ruby/csv/commit/dbd860c1cd
* [ruby/csv] RDoc: summary lists for options (#154)Burdette Lamar2020-07-201-71/+125
| | | | | | | | | | | | | * 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 https://github.com/ruby/csv/commit/72d8a25dc9
* [ruby/csv] RDoc remark about instance methods (#152)Burdette Lamar2020-07-201-1/+8
| | | | https://github.com/ruby/csv/commit/76379bbe62
* [ruby/csv] Revised introductory RDoc (#151)Burdette Lamar2020-07-201-68/+147
| | | | https://github.com/ruby/csv/commit/60f6f1c28f
* [ruby/csv] Enhanced RDoc for filter (#149)Burdette Lamar2020-07-201-44/+70
| | | | | | | | | | | | | * 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> https://github.com/ruby/csv/commit/2c347f9a3d
* [ruby/csv] Enhancements for RDoc (#148)Burdette Lamar2020-07-201-19/+52
| | | | | Co-authored-by: Sutou Kouhei <kou@cozmixng.org> https://github.com/ruby/csv/commit/25dd4cddbb
* [ruby/csv] Organize files in doc/ (#145)Burdette Lamar2020-07-201-30/+30
| | | | https://github.com/ruby/csv/commit/bc9ea859b0
* [ruby/csv] RDoc for parse_line (adds headers examples) (#143)Burdette Lamar2020-07-201-16/+40
| | | | | | | * RDoc for parse_line (adds headers examples) * RDoc for parse_line (adds headers examples) https://github.com/ruby/csv/commit/a161be928e
* [ruby/csv] Added headers to RDoc for CSV.foreach (#142)Burdette Lamar2020-07-201-7/+44
| | | | | | | | | * Added headers: to RDoc for CSV.foreach * Correct options remark for CSV.generate * Improve citation for option headers https://github.com/ruby/csv/commit/b01945ec3a
* [ruby/csv] Add headers cases to CSV.parse (#141)Burdette Lamar2020-07-201-2/+54
| | | | | | | | | * Add headers cases to CSV.parse * Adjust call-seq for CSV.parse * Update csv.rb https://github.com/ruby/csv/commit/848c760c43
* [ruby/csv] doc: fix return value of open {} and use File.open {} (#139)Burdette Lamar2020-07-201-4/+8
| | | | | | | * Enhanced RDoc for CSV * Repair example code for foreach https://github.com/ruby/csv/commit/16b425eb37
* [ruby/csv] Rdoc (#137)Burdette Lamar2020-07-201-41/+116
| | | | | Enhancements for open, parse, minor tweaks. https://github.com/ruby/csv/commit/35392f4e45
* [ruby/csv] Add document for CSV.instance (#136)Burdette Lamar2020-07-201-66/+94
| | | | | Co-authored-by: Sutou Kouhei <kou@cozmixng.org> https://github.com/ruby/csv/commit/85e293c1ba
* [ruby/csv] Add RDoc links for delegated methods (#135)Burdette Lamar2020-07-201-34/+35
| | | | https://github.com/ruby/csv/commit/1a4b96b418
* [ruby/csv] Add `invalid: :replace` for `CSV.open` (#130)Koichi ITO2020-07-201-2/+5
| | | | | This PR adds `invalid: :replace` for `CSV.open`. It is a PR similar to #129. https://github.com/ruby/csv/commit/5bf687341c
* [ruby/csv] Add `undef: :replace` for `CSV.open` (#129)Koichi ITO2020-07-201-0/+7
| | | | | | | | | 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. https://github.com/ruby/csv/commit/cff8b18480
* [ruby/csv] RDoc for foreach, generate (#127)Burdette Lamar2020-07-201-22/+123
| | | | | | | * Rdoc for foreach * Enhanced Rdoc for CSV.generate https://github.com/ruby/csv/commit/8c26c0ab1f
* [ruby/csv] Enhanced Rdoc (#124)Burdette Lamar2020-07-201-26/+100
| | | | | | | | | | | | | | | | | * 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 https://github.com/ruby/csv/commit/0d42df39cb
* [ruby/csv] Don't drop stack trace in CSV.parse_lineSutou Kouhei2020-07-201-1/+1
| | | | | | | | GitHub: fix GH-120 Reported by Kyle d'Oliveira. Thanks!!! https://github.com/ruby/csv/commit/2959483f90
* [ruby/csv] Enhanced Rdoc for CSV (#122)Burdette Lamar2020-07-201-216/+322
| | | | https://github.com/ruby/csv/commit/cd670595d5
* [ruby/csv] Fix docs for :strip option (#114)TOMITA Masahiro2020-07-201-1/+1
| | | | https://github.com/ruby/csv/commit/fb10925271
* [ruby/csv] Ensuring StringIO's encoding in CSV.generate (#111)Seiei Miyagi2020-07-201-1/+2
| | | | https://github.com/ruby/csv/commit/dbf55ef008
* Import CSV 3.1.2 (#2547)Sutou Kouhei2019-10-121-378/+398
|
* Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans2019-09-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix keyword argument separation issues in libJeremy Evans2019-08-301-18/+18
| | | | Mostly requires adding ** in either calls or method definitions.
* Fix a typo [ci skip]Kazuhiro NISHIYAMA2019-08-131-1/+1
|
* Fix a typo in inspectKazuhiro NISHIYAMA2019-07-251-1/+1
|
* [ruby/csv] add options doc :quote_empty (#89)kawa_tech2019-07-141-1/+4
| | | | https://github.com/ruby/csv/commit/5ca8d79f60
* [ruby/csv] Add options doc: :write_converters, :write_nil_value, ↵Masafumi Koba2019-07-141-3/+13
| | | | | | :write_empty_value (#87) https://github.com/ruby/csv/commit/5923ee08b7
* [ruby/csv] add document of strip (#88)hayashiyoshino2019-07-141-1/+5
| | | | | | | | * add document of strip * modify typo https://github.com/ruby/csv/commit/de0257dc31
* [ruby/csv] Don't raise on eof?Kouhei Sutou2019-07-141-0/+11
| | | | | | | | GitHub: fix #86 Reported by krororo. Thanks!!! https://github.com/ruby/csv/commit/5a8d9d9297
* Import CSV 3.0.8kou2019-04-141-28/+101
| | | | | | | | This includes performance improvements and backward incompatibility fixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Upgrade CSV to 3.0.4kou2019-01-251-9/+12
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Import CSV 3.0.2kou2018-12-231-615/+222
| | | | | | | | This includes performance improvement especially writing. Writing is about 2 times faster. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Merge csv-3.0.0 from ruby/csv repository.hsbt2018-09-051-4/+8
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Merge csv-1.0.2 from upstream.hsbt2018-05-091-796/+219
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e