winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 02e720c43cdedd07890799703327efd00d4ff5a5
parent b3f7abcb4a327a28da774d91ec9774713688b4ac
Author: KEINOS <github+fork-qiita-news@keinos.com>
Date:   Sat, 26 Jul 2025 02:21:34 +0000

Merge remote-tracking branch 'upstream/master'

Diffstat:
M.github/actions/spelling/expect.txt | 2++
Msrc/AppInstallerSharedLib/YamlWrapper.cpp | 26+++++++++++++++++++-------
2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt @@ -47,6 +47,7 @@ awgs azurewebsites Baz bcp +BEBOM BEFACEF bfd BFirst @@ -268,6 +269,7 @@ kool ktf LCID learnxinyminutes +LEBOM lhs LIBYAML liv diff --git a/src/AppInstallerSharedLib/YamlWrapper.cpp b/src/AppInstallerSharedLib/YamlWrapper.cpp @@ -343,23 +343,35 @@ namespace AppInstaller::YAML::Wrapper void Parser::PrepareInput() { - constexpr char c_utf16BOM[2] = { static_cast<char>(0xFF), static_cast<char>(0xFE) }; + constexpr char c_utf16LEBOM[2] = { static_cast<char>(0xFF), static_cast<char>(0xFE) }; + constexpr char c_utf16BEBOM[2] = { static_cast<char>(0xFE), static_cast<char>(0xFF) }; constexpr char c_utf8BOM[3] = { static_cast<char>(0xEF), static_cast<char>(0xBB), static_cast<char>(0xBF) }; - // If input has a BOM, we want to pass it on through. + // If input has a BOM, we want to remove it to prevent errors with checking for comments within the input document. + // Check for UTF-16 BOMs - if (m_input.size() >= 2 && - ((m_input[0] == c_utf16BOM[0] && m_input[1] == c_utf16BOM[1]) || (m_input[0] == c_utf16BOM[1] && m_input[1] == c_utf16BOM[0]))) + if (m_input.size() >= sizeof(c_utf16LEBOM) && std::memcmp(m_input.data(), c_utf16LEBOM, sizeof(c_utf16LEBOM)) == 0) + { + AICLI_LOG(YAML, Verbose, << "Found UTF-16 LE BOM"); + yaml_parser_set_encoding(&m_parser, YAML_UTF16LE_ENCODING); // Without the BOM, the encoding must be explicitly set + m_input.erase(0, sizeof(c_utf16LEBOM)); // Remove the BOM from the input + return; + } + + if (m_input.size() >= sizeof(c_utf16BEBOM) && std::memcmp(m_input.data(), c_utf16BEBOM, sizeof(c_utf16BEBOM)) == 0) { - AICLI_LOG(YAML, Verbose, << "Found UTF-16 BOM"); + AICLI_LOG(YAML, Verbose, << "Found UTF-16 BE BOM"); + yaml_parser_set_encoding(&m_parser, YAML_UTF16BE_ENCODING); // Without the BOM, the encoding must be explicitly set + m_input.erase(0, sizeof(c_utf16BEBOM)); // Remove the BOM from the input return; } // Check for UTF-8 BOM - if (m_input.size() >= 3 && - (m_input[0] == c_utf8BOM[0] && m_input[1] == c_utf8BOM[1] && m_input[2] == c_utf8BOM[2])) + if (m_input.size() >= sizeof(c_utf8BOM) && std::memcmp(m_input.data(), c_utf8BOM, sizeof(c_utf8BOM)) == 0) { AICLI_LOG(YAML, Verbose, << "Found UTF-8 BOM"); + yaml_parser_set_encoding(&m_parser, YAML_UTF8_ENCODING); // Without the BOM, the encoding must be explicitly set + m_input.erase(0, sizeof(c_utf8BOM)); // Remove the BOM from the input return; }