Uh oh!
There was an error while loading. Please reload this page.
Add CSV::InvalidEncodingError - #287
Merged
Merged
Conversation
kou
approved these changes
Sep 12, 2023
| # The error thrown when the parser encounters invalid encoding in CSV. | ||
| class InvalidEncodingError < MalformedCSVError | ||
| def initialize(encoding, line_number) |
Member
There was a problem hiding this comment.
How about adding a reader for the target encoding?
Suggested change
| definitialize(encoding,line_number) | |
| attr_reader:encoding | |
| definitialize(encoding,line_number) | |
| @encoding=encoding |
Member
There was a problem hiding this comment.
We can't get the target encoding if we don't set it to @encoding. (See the above suggestion.)
shibaaaaforce-pushed
the
add-csv-invalid-encoding-error
branch
from
September 13, 2023 09:03
cb0a680 to
f2369dbComparekou
reviewed
Sep 13, 2023
| # The error thrown when the parser encounters invalid encoding in CSV. | ||
| class InvalidEncodingError < MalformedCSVError | ||
| def initialize(encoding, line_number) |
Member
There was a problem hiding this comment.
We can't get the target encoding if we don't set it to @encoding. (See the above suggestion.)
| end | ||
| CSV.open(@input.path, encoding: "EUC-JP") do |csv| | ||
| error = assert_raise(CSV::MalformedCSVError) do | ||
| error = assert_raise(CSV::InvalidEncodingError) do |
Member
There was a problem hiding this comment.
Could you also change the below assert_equal(...) to the following?
assert_equal([Encoding::EUC_JP,"Invalid byte sequence in EUC-JP in line 1."],[error.encoding,error.message])| csv = CSV.new("valid,x\rinvalid,\xF8\r".force_encoding("UTF-8"), | ||
| encoding: "UTF-8", row_sep: "\r") | ||
| error = assert_raise(CSV::MalformedCSVError) do | ||
| error = assert_raise(CSV::InvalidEncodingError) do |
To handle encoding errors in CSV parsing with the appropriate error class
shibaaaaforce-pushed
the
add-csv-invalid-encoding-error
branch
from
September 13, 2023 22:18
f2369db to
0aa7d2fComparekou
commented
Sep 14, 2023
Member
Thanks! |
kou
commented
Sep 14, 2023
Member
Do you want a new version soon? |
shibaaaa
commented
Sep 14, 2023
ContributorAuthor
No I don't, thanks. |
matzbot pushed a commit
to ruby/ruby
that referenced
this pull request
Oct 3, 2023
(ruby/csv#287) To handle encoding errors in CSV parsing with the appropriate error class ruby/csv@68b44887e5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To handle encoding errors in CSV parsing with the appropriate error class