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

[Fixes #2345] Quick fix for handling files with BOMs in them. #2353

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/kOS.Safe/Persistence/FileContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,25 @@ public FileContent(string content) : this()
{
Bytes = fileEncoding.GetBytes(content);
}

public FileContent(byte[] content) : this()
{
Bytes = content;
string decodedString;

// Issue #2345: kOS reading UTF-8 can't handle a file with a BOM in it.
//
// In order to allow kOS to read files with a BOM in them
// we first pass them through a StreamReader, which handles
// the BOM and gives us a string with only the text data.
using (MemoryStream ms = new MemoryStream(content))
{
using (StreamReader sr = new StreamReader(ms))
{
decodedString = sr.ReadToEnd();
}
}

Bytes = fileEncoding.GetBytes(decodedString);
}

public FileContent(List<CodePart> parts) : this()
Expand Down