Skip to content

Fix #5614: Handle UTF-8 BOM in EPW files#5629

Open
wnykuang wants to merge 1 commit into
NatLabRockies:developfrom
wnykuang:agent/fix-epw-utf8-bom
Open

Fix #5614: Handle UTF-8 BOM in EPW files#5629
wnykuang wants to merge 1 commit into
NatLabRockies:developfrom
wnykuang:agent/fix-epw-utf8-bom

Conversation

@wnykuang

@wnykuang wnykuang commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix EpwFile cannot process epw file #5614
  • Strip a leading UTF-8 byte order mark before parsing an EPW LOCATION header.
  • Add a regression test proving BOM-prefixed EPW content remains loadable.

Root cause

EpwFile::parse passed the first line through unchanged, while parseLocation requires the first comma-delimited field to equal LOCATION. For UTF-8-with-BOM files, that field begins with the bytes EF BB BF, so a valid header was reported as missing its LOCATION specifier.

The fix only removes a UTF-8 BOM at the beginning of the first line. Existing validation remains unchanged, and this does not attempt to decode UTF-16 or UTF-32 files.

User impact

EPW files saved as UTF-8 with BOM, including the file attached to #5614, can now be processed normally.

Validation

  • Added Filetypes.EpwFile_UTF8BOM and observed it fail before the implementation change and pass afterward.
  • Ran all 25 Filetypes.EpwFile* tests successfully.
  • Re-ran the original 2.5 MB EPW attachment from EpwFile cannot process epw file #5614 and confirmed the parsing failure no longer occurs.
  • Ran git diff --check successfully.

Fixes #5614.

Strip a leading UTF-8 byte order mark before validating the LOCATION header. Add a regression test covering BOM-prefixed EPW content.\n\nFixes NatLabRockies#5614.
@wnykuang wnykuang changed the title Fix EPW parsing for UTF-8 BOM Fix #5614: Handle UTF-8 BOM in EPW files Jul 11, 2026
@wnykuang wnykuang marked this pull request as ready for review July 11, 2026 21:01
@wnykuang wnykuang marked this pull request as draft July 11, 2026 21:04
@wnykuang wnykuang marked this pull request as ready for review July 11, 2026 21:06

namespace openstudio {

constexpr std::string_view UTF8_BOM{"\xEF\xBB\xBF", 3};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok. Not my prefered style of declaration, but it's valid and defensive (would work with a null byte in the middle too)

Comment on lines +4900 to +4902
if ((i == 0) && line.starts_with(UTF8_BOM)) {
line.erase(0, UTF8_BOM.size());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EpwFile cannot process epw file

2 participants