Skip to content

Yield explicitly supplied headers only once when reading incrementally - #368

Open
OskarEichler wants to merge 1 commit into
ruby:mainfrom
OskarEichler:codex/csv-header_once
Open

Yield explicitly supplied headers only once when reading incrementally#368
OskarEichler wants to merge 1 commit into
ruby:mainfrom
OskarEichler:codex/csv-header_once

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Clear the pending raw headers before yielding their synthetic row. This lets later shift/each calls advance into data and reach EOF, while rewind rebuilds the parser.

Reproduction

csv = CSV.new("1,2\n", headers: %w[a b], return_headers: true); 3.times { p csv.shift } returns the header three times. This became observable when #363 removed the persistent parser enumerator.

Verification

108 focused checks: 72 failures on the release, zero with the patch, across array/string/empty headers, converters, unconverted fields, incremental reads, repeated EOF, and rewind.

This isolated patch passes the unchanged upstream suite in both normal and CSV_PARSER_SCANNER_TEST=yes modes: 527 tests / 4,050 assertions in each mode, zero failures/errors. Commands use Ruby 4.0.6 through rbenv (bundle exec ruby run-test.rb). Syntax and git diff --check pass. The combined release-based consumer branch also passes gem build and rake warning:error rdoc.

No tests were added or changed, per the requesting project's explicit no-new-tests policy. Focused checks and measurements live outside this repository. The upstream no-RuboCop policy is respected. Verification was local on macOS/Ruby 4.0.6; the supported OS/Ruby matrix was not run locally. Current main and installed 3.3.6 share base commit 0873ab362d996f12796c3c3e8998b5be657a9b12; no unrelated changes are included.

Breaking changes and limitations

None intended. Repeated incremental reads no longer emit an endless stream of synthetic headers.

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.

1 participant