Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add `undef: :replace` for `CSV.open` #129

Merged
merged 1 commit into from Jun 1, 2020

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 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
@@ -1021,6 +1026,7 @@ def open(filename, mode="r", **options)
# 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))

This comment has been minimized.

@kou

kou Jun 1, 2020
Member

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

This comment has been minimized.

@koic

koic Jun 1, 2020
Author Contributor

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 koic:add_undef_replace_option_for_csv_open branch from 4c027bf to 625f721 Jun 1, 2020
@kou kou merged commit cff8b18 into ruby:master Jun 1, 2020
17 checks passed
17 checks passed
Benchmark: Ruby 2.7: macos-latest
Details
Normal test: Ruby 2.5: macos-latest
Details
Benchmark: Ruby 2.7: ubuntu-latest
Details
Normal test: Ruby 2.5: ubuntu-latest
Details
Benchmark: Ruby 2.7: windows-latest
Details
Normal test: Ruby 2.5: windows-latest
Details
Normal test: Ruby 2.6: macos-latest
Details
Normal test: Ruby 2.6: ubuntu-latest
Details
Normal test: Ruby 2.6: windows-latest
Details
Normal test: Ruby 2.7: macos-latest
Details
Normal test: Ruby 2.7: ubuntu-latest
Details
Normal test: Ruby 2.7: windows-latest
Details
Scanner test: Ruby 2.7: macos-latest
Details
Scanner test: Ruby 2.7: ubuntu-latest
Details
Scanner test: Ruby 2.7: windows-latest
Details
Gem test
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@kou
Copy link
Member

@kou kou commented Jun 1, 2020

Thanks!

@koic koic deleted the koic:add_undef_replace_option_for_csv_open branch Jun 1, 2020
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
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.