Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 21 additions & 4 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,31 @@ void CascadiaSettings::_validateAllSchemesExist()
{
if (appearance && !colorSchemes.HasKey(appearance.DarkColorSchemeName()))
{
// Clear the user set dark color scheme. We'll just fallback instead.
appearance.ClearDarkColorSchemeName();
// If the leaf owns the bad name, clear it so the system default
// takes effect. If the name was inherited from a parent (fragment,
// defaults.json, etc.), the clear would be a no-op because the
// leaf's optional is already nullopt. In that case we must
// explicitly shadow the parent's value with the system default.
if (appearance.HasDarkColorSchemeName())
{
appearance.ClearDarkColorSchemeName();
}
else
{
appearance.DarkColorSchemeName(L"Campbell");
}
foundInvalidDarkScheme = true;
}
if (appearance && !colorSchemes.HasKey(appearance.LightColorSchemeName()))
{
// Clear the user set light color scheme. We'll just fallback instead.
appearance.ClearLightColorSchemeName();
if (appearance.HasLightColorSchemeName())
{
appearance.ClearLightColorSchemeName();
}
else
{
appearance.LightColorSchemeName(L"Campbell");
}
foundInvalidLightScheme = true;
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/cascadia/UnitTests_SettingsModel/DeserializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace SettingsModelUnitTests
TEST_METHOD(TestLayeringNameOnlyProfiles);
TEST_METHOD(TestHideAllProfiles);
TEST_METHOD(TestInvalidColorSchemeName);
TEST_METHOD(TestInvalidColorSchemeNameFromFragmentFallsBack);
TEST_METHOD(TestHelperFunctions);
TEST_METHOD(TestCloseOnExitParsing);
TEST_METHOD(TestCloseOnExitCompatibilityShim);
Expand Down Expand Up @@ -743,6 +744,43 @@ namespace SettingsModelUnitTests
}
}

void DeserializationTests::TestInvalidColorSchemeNameFromFragmentFallsBack()
{
Log::Comment(NoThrowString().Format(
L"Ensure that setting a profile's scheme to a nonexistent scheme via a fragment causes a warning and falls back correctly."));

static constexpr std::string_view userJson{ R"({
"profiles": [
{
"name" : "profile0"
}
]
})" };

static constexpr std::string_view fragmentJson{ R"({
"profiles": [
{
"name": "profile0",
"colorScheme": "InvalidSchemeName"
}
]
})" };

implementation::SettingsLoader loader{ userJson, implementation::LoadStringResource(IDR_DEFAULTS) };
loader.MergeInboxIntoUserSettings();
loader.MergeFragmentIntoUserSettings(L"fragment", {}, fragmentJson);
loader.FinalizeLayering();

auto settings = winrt::make_self<implementation::CascadiaSettings>(std::move(loader));
auto profile = settings->AllProfiles().GetAt(0);

VERIFY_ARE_EQUAL(1u, settings->Warnings().Size());
VERIFY_ARE_EQUAL(SettingsLoadWarnings::UnknownColorScheme, settings->Warnings().GetAt(0));

VERIFY_ARE_EQUAL(L"Campbell", profile.DefaultAppearance().DarkColorSchemeName());
VERIFY_ARE_EQUAL(L"Campbell", profile.DefaultAppearance().LightColorSchemeName());
}

void DeserializationTests::ValidateColorSchemeInCommands()
{
Log::Comment(NoThrowString().Format(
Expand Down
Loading