Open
Conversation
…OM characters instead of trimming whitespace
Collaborator
|
Thank you for opening this PR. I've confirmed that these changes don't seem to cause any problems when used with the CLI or online validator. I would like a little more information about your use case: you mentioned an error that would occur. What is the error message, and where in the process would that error occur? |
Author
|
The file mentioned above fails with the message below. It looks like the process never really gets past trying to open the file before it fails. We're using this package directly in our code. We are not using the CLI or the online validator. file:///node_modules/hpt-validator/lib/utils.js:45
chunk = chunk.trimStart();
^
TypeError: chunk.trimStart is not a function
at removeBOM (file:///node_modules/hpt-validator/lib/utils.js:45:23)
at ChecksumStream.<anonymous> (file:///node_modules/hpt-validator/lib/versions/common/json.js:29:24)
at ChecksumStream.emit (node:events:518:28)
at ChecksumStream.emit (node:domain:489:12)
at ChecksumStream.Readable.read (node:internal/streams/readable:782:10)
at flow (node:internal/streams/readable:1283:53)
at resume_ (node:internal/streams/readable:1262:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
|
Collaborator
|
This change looks good! Could you add some test cases to show the function handling a |
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 free
to 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.
Fixes issues with
removeBOMto properly handle UTF-8 BOM.Problem
The current implementation of
removeBOM()inutils.jshas critical issues:trimStart()removes whitespace rather than removing the BOM bytesSolution
The updated implementation:
Buffer.isBuffer()to avoid unnecessary conversionsslice(3)which removes the BOM characters instead of whitespacecharCodeAt(0) === 0xfeffResult
This ensures that files with BOMs are correctly processed by the validator, which prevents validation errors and inconsistencies in the processing pipeline.
Our use case is that we're streaming files from a S3 bucket to a Lambda to validate them. We found some specific files that would fail with the error below. But if we downloaded the file and used the CLI or online validator the file validated without issue. These updates fix this S3 streaming issue and allow the validator to function properly.
Test Plan
We noticed this issue with this MRF: https://smmcnj.com/wp-content/uploads/2024/12/1568825545_SaintMichaelsMedicalCenter_standardcharges.json
That MRF has been tested and verified. I initially made these updates our code base back in June. We've tested around 200 MRFs since then and have seen no issues.