Skip to content

Conversation

@koic
Copy link
Contributor

@koic koic commented Jun 1, 2020

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.

@koic
Copy link
Contributor Author

koic commented Jun 1, 2020

#90 has been opened for this issue but lacks activity.
I came across an opportunity to want to use this option with CSV.open and I've opened it as a new PR.

lib/csv.rb Outdated
# wrap a File opened with the remaining +args+ with no newline
# decorator
file_opts = {universal_newline: false}.merge(options)
file_opts.merge!(undef: options.delete(:undef), replace: options.delete(:replace))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file_opts.merge!(undef: options.delete(:undef), replace: options.delete(:replace))
options.delete(:undef)
options.delete(:replace)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it. Thanks for your review!

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.
@koic koic force-pushed the add_undef_replace_option_for_csv_open branch from 4c027bf to 625f721 Compare June 1, 2020 23:03
@kou kou merged commit cff8b18 into ruby:master Jun 1, 2020
@kou
Copy link
Member

kou commented Jun 1, 2020

Thanks!

@koic koic deleted the add_undef_replace_option_for_csv_open branch June 1, 2020 23:32
koic added a commit to koic/csv that referenced this pull request Jun 3, 2020
This PR adds `invalid: :replace` for `CSV.open`. It is a PR similar to ruby#129.

And this PR uses `String#scrub` to prevent the following `ArgumentError`.

```ruby
/[,"]/.match?("\x82\xA0")       #=> ArgumentError (invalid byte sequence in UTF-8)
/[,"]/.match?("\x82\xA0".scrub) #=> false
```
koic added a commit to koic/csv that referenced this pull request Jun 4, 2020
This PR adds `invalid: :replace` for `CSV.open`. It is a PR similar to ruby#129.

And this PR uses `String#scrub` to prevent the following `ArgumentError`.

```ruby
/[,"]/.match?("\x82\xA0")       #=> ArgumentError (invalid byte sequence in UTF-8)
/[,"]/.match?("\x82\xA0".scrub) #=> false
```
koic added a commit to koic/csv that referenced this pull request Jun 4, 2020
This PR adds `invalid: :replace` for `CSV.open`. It is a PR similar to ruby#129.

And this PR uses `String#scrub` to prevent the following `ArgumentError`.

```ruby
/[,"]/.match?("\x82\xA0")       #=> ArgumentError (invalid byte sequence in UTF-8)
/[,"]/.match?("\x82\xA0".scrub) #=> false
```
kou pushed a commit that referenced this pull request Jun 4, 2020
This PR adds `invalid: :replace` for `CSV.open`. It is a PR similar to #129.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants