You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@abcdefg-1234567 Great! Do you want to work on fixing this problem?
Could you share a script that produces a CSV that reproduces this problem as the first step?
@kou
Yes, I would like to.
I used a CSV file made by a tool for spreadsheet and IDE to reproduce this problem.
So, I will make script that produces a CSV.
OK. Let's reduce the reproducible CSV size as much as possible as the next step for easy to debug.
If it's difficult, we can start debugging with the reproducible CSV. #279 (comment) may help you.
InputsScanner acts as logically one StringScanner with multiple inputs. (StringScanner can't work with multiple strings.)
CSV::Parser may want to push back read data. For example, if skip_lines is specified, CSV::Parser may push back read data. CSV::Parser reads a line from its scanner (CSV::Parser::Scanner or CSV::Parser::InputsScanner) to check whether the line should be skipped. If the read line isn't skip target, CSV::Parser pushes back the read line and parses the line as a CSV line. keep_start/keep_drop/keep_back/keep_end are for it.
adjust_last_keep is related to these keep_* methods.InputsScanner processes multiple inputs. So the target data (for example, one line for skip_lines) may exist in multiple inputs. For example, "# a", "bc" and "\n" are one line but they are 3 inputs. adjust_last_keep is for the situation. If we need to concatenate data from multiple inputs, adjust_last_keep does it.
Activity
tmatsuura1 commentedon May 14, 2023
@kou
I could reproduce this bug at hand.
kou commentedon May 14, 2023
Thanks for your report.
It may be a bug of internal chunk based stream parser:
csv/lib/csv/parser.rb
Lines 299 to 308 in 22e62bc
@abcdefg-1234567 Great! Do you want to work on fixing this problem?
Could you share a script that produces a CSV that reproduces this problem as the first step?
tmatsuura1 commentedon May 15, 2023
@kou
Yes, I would like to.
I used a CSV file made by a tool for spreadsheet and IDE to reproduce this problem.
So, I will make script that produces a CSV.
tmatsuura1 commentedon May 20, 2023
@kou
I came up with the following code that creates a csv.
However, I do not know how to make the following state by code.
I have confirmed that the bug is reproduced when the following conditions are set manually using the IDE.
Could you please give me any ideas?
GabrielNagy commentedon May 20, 2023
hey @abcdefg-1234567 you can use the following:
tmatsuura1 commentedon May 20, 2023
@GabrielNagy
Thank you!
kou commentedon May 20, 2023
OK. Let's reduce the reproducible CSV size as much as possible as the next step for easy to debug.
If it's difficult, we can start debugging with the reproducible CSV.
#279 (comment) may help you.
tmatsuura1 commentedon May 21, 2023
I have confirmed that the bug will not reproduce if the csv is less than 2048 rows.
tmatsuura1 commentedon Jun 11, 2023
I have confirmed the following.
The result of "value = parse_column_value (line 1030 of parser.rb)" when @ lineno=2048 is "AAAA1234567890AAAAA1234567890".
I am also wondering if changes are needed around the adjust_last_keep method.
@kou
Could you please explain the role of this method?
kou commentedon Jun 12, 2023
Sure.
#adjust_last_keepwas introduced for fixing https://bugs.ruby-lang.org/issues/18245 .InputsScanneracts as logically oneStringScannerwith multiple inputs. (StringScannercan't work with multiple strings.)CSV::Parsermay want to push back read data. For example, ifskip_linesis specified,CSV::Parsermay push back read data.CSV::Parserreads a line from its scanner (CSV::Parser::ScannerorCSV::Parser::InputsScanner) to check whether the line should be skipped. If the read line isn't skip target,CSV::Parserpushes back the read line and parses the line as a CSV line.keep_start/keep_drop/keep_back/keep_endare for it.adjust_last_keepis related to thesekeep_*methods.InputsScannerprocesses multiple inputs. So the target data (for example, one line forskip_lines) may exist in multiple inputs. For example,"# a","bc"and"\n"are one line but they are 3 inputs.adjust_last_keepis for the situation. If we need to concatenate data from multiple inputs,adjust_last_keepdoes it.I hope that this explanation helps you.
tmatsuura1 commentedon Jun 17, 2023
Thank you for your detailed explanation!
I will refer to this and continue the investigation.
kou commentedon Jun 26, 2023
Including line number in line contents will helpful:
Output with the test file:
It seems that the last line was used twice.
kou commentedon Jun 26, 2023
I cloud reproduce this with the script:
[ruby/csv] Fix a bug that the same line is used multiple times
GabrielNagy commentedon Jul 4, 2023
Thanks for fixing this!
Fix a bug that the same line is used multiple times