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.