From dba918beab1096092d31dcddece40b1cb74d2841 Mon Sep 17 00:00:00 2001 From: Summon528 Date: Sat, 15 Jun 2019 03:29:40 +0800 Subject: [PATCH] Ignore UTF-8 BOM (#1266) --- .../TerminalApp/CascadiaSettingsSerialization.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp index 547991437..ab50a4646 100644 --- a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp @@ -25,6 +25,8 @@ static constexpr std::string_view KeybindingsKey{ "keybindings" }; static constexpr std::string_view GlobalsKey{ "globals" }; static constexpr std::string_view SchemesKey{ "schemes" }; +static constexpr std::string_view Utf8Bom{ u8"\uFEFF" }; + // Method Description: // - Creates a CascadiaSettings from whatever's saved on disk, or instantiates // a new one with the default values. If we're running as a packaged app, @@ -48,12 +50,19 @@ std::unique_ptr CascadiaSettings::LoadAll(const bool saveOnLoa { const auto actualData = fileData.value(); + // Ignore UTF-8 BOM + auto actualDataStart = actualData.c_str(); + if (actualData.compare(0, Utf8Bom.size(), Utf8Bom) == 0) + { + actualDataStart += Utf8Bom.size(); + } + // Parse the json data. Json::Value root; std::unique_ptr reader{ Json::CharReaderBuilder::CharReaderBuilder().newCharReader() }; std::string errs; // This string will recieve any error text from failing to parse. // `parse` will return false if it fails. - if (!reader->parse(actualData.c_str(), actualData.c_str() + actualData.size(), &root, &errs)) + if (!reader->parse(actualDataStart, actualData.c_str() + actualData.size(), &root, &errs)) { // TODO:GH#990 display this exception text to the user, in a // copy-pasteable way.