Skip to content

fix: keep all fields and sanitize the CSV header in export_csv - #55

Open
chiruu12 wants to merge 1 commit into
brightdata:mainfrom
chiruu12:fix/export-csv-fields-and-header
Open

fix: keep all fields and sanitize the CSV header in export_csv#55
chiruu12 wants to merge 1 commit into
brightdata:mainfrom
chiruu12:fix/export-csv-fields-and-header

Conversation

@chiruu12

Copy link
Copy Markdown

Fixes two issues in export_csv.

Dropped columns (#53). The column list came from data[0].keys(), so a key that first appears on a later record was never written and nothing was raised. Scraper output is heterogeneous, optional fields are absent when a page does not have them, so this loses real data on ordinary output. export_json and export_jsonl keep every key, so the same result set exported differently depending on format. Columns now come from every record, in first-seen order.

Unsanitized header (#54). #52 added _sanitize_csv_cell for values, but writeheader() wrote the field names unchanged, and those names come from keys in the scraped payload. A key like =HYPERLINK("http://evil","x") still evaluated on open. The header now goes through the same sanitizer, including when fields= is passed explicitly. sanitize=False leaves the header byte-exact as before.

Tests: 5 new cases, 21 passing in the two export_csv files. Each new case fails with the source change reverted and the tests kept.

Copilot AI lite review requested due to automatic review settings August 16, 2026 20:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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