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

Remove byte-order mark from JSON stream and first CSV chunk #53

Merged
merged 4 commits into from
Aug 20, 2024

Conversation

mint-thompson
Copy link
Collaborator

@mint-thompson mint-thompson commented Aug 11, 2024

Problem

When validating JSON with a readable stream, the presence of a byte-order mark causes a parser error.

When validating CSV, an initial BOM will be part of the first column name. If the first column name is also quoted, this means that the value will not be recognized as quoted. This causes the first column to not match any of the expected column names.

Solution

When reading the first chunk of a JSON stream, check for the presence of a byte-order mark. If it is present, remove it.

When reading the first chunk of CSV, check for the presence of a byte-order mark. If it is present, remove it.

Test Plan

A test case that uses a JSON file encoded as utf-8 with BOM is added to test this change.

A test case that uses CSV file encoded as utf-8 with BOM is added to test this change. The first column name in the file is quoted.

EDIT: Updated 2024/08/16 with information about the CSV changes (984cb6d)

When JSON input is a readable stream, a byte-order mark may be present
at the beginning of the stream. When reading the first chunk of the
stream, check for the presence of the byte-order mark. Remove it if it
is present.
When parsing a CSV from a source that includes a byte-order mark (BOM),
the BOM is present at the time the parser attempts to determine if the
first column name is quoted. When the BOM is present, the parser does
not recognize that the column is quoted, resulting in a failure to match
an expected column name. Remove the BOM (if present) from the first
chunk so that a quoted column name will be recognized and parsed as a
quoted value.
@mint-thompson mint-thompson changed the title Remove byte-order mark from JSON stream Remove byte-order mark from JSON stream and first CSV chunk Aug 16, 2024
Copy link
Collaborator

@shaselton-usds shaselton-usds left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good!

@shaselton-usds shaselton-usds merged commit d20f463 into main Aug 20, 2024
4 checks passed
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.

3 participants