mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-10 00:48:23 -06:00
Add clamping of initial rows and columns settings (#16989)
This clamps the initial rows and columns settings in two areas: - When reading the JSON file - In the settings dialogue For consistency, I've also added a minimum value to the NumberBoxes even though the default Minimum is 1. The Maximum and Minimum are taken from the JSON Schema file (Min 1, Max 999). Closes #11957 --------- Co-authored-by: Dustin L. Howett <dustin@howett.net>
This commit is contained in:
parent
5f1015953f
commit
ad0c28b30d
@ -184,6 +184,8 @@
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Maximum="999"
|
||||
Minimum="1"
|
||||
Style="{StaticResource LaunchSizeNumberBoxStyle}"
|
||||
Value="{x:Bind ViewModel.InitialCols, Mode=TwoWay}" />
|
||||
<TextBlock x:Uid="Globals_InitialRows"
|
||||
@ -195,6 +197,8 @@
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Maximum="999"
|
||||
Minimum="1"
|
||||
Style="{StaticResource LaunchSizeNumberBoxStyle}"
|
||||
Value="{x:Bind ViewModel.InitialRows, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
|
||||
@ -137,6 +137,17 @@ void GlobalAppSettings::LayerJson(const Json::Value& json, const OriginTag origi
|
||||
MTSM_GLOBAL_SETTINGS(GLOBAL_SETTINGS_LAYER_JSON)
|
||||
#undef GLOBAL_SETTINGS_LAYER_JSON
|
||||
|
||||
// GH#11975 We only want to allow sensible values and prevent crashes, so we are clamping those values
|
||||
// We only want to assign if the value did change through clamping,
|
||||
// otherwise we could end up setting defaults that get persisted
|
||||
if (this->HasInitialCols())
|
||||
{
|
||||
this->InitialCols(std::clamp(this->InitialCols(), 1, 999));
|
||||
}
|
||||
if (this->HasInitialRows())
|
||||
{
|
||||
this->InitialRows(std::clamp(this->InitialRows(), 1, 999));
|
||||
}
|
||||
LayerActionsFrom(json, origin, true);
|
||||
|
||||
JsonUtils::GetValueForKey(json, LegacyReloadEnvironmentVariablesKey, _legacyReloadEnvironmentVariables);
|
||||
|
||||
@ -47,6 +47,7 @@ namespace SettingsModelUnitTests
|
||||
TEST_METHOD(ValidateKeybindingsWarnings);
|
||||
TEST_METHOD(ValidateColorSchemeInCommands);
|
||||
TEST_METHOD(ValidateExecuteCommandlineWarning);
|
||||
TEST_METHOD(TestClampingOfStartupColumnAndViewProperties);
|
||||
TEST_METHOD(TestTrailingCommas);
|
||||
TEST_METHOD(TestCommandsAndKeybindings);
|
||||
TEST_METHOD(TestNestedCommandWithoutName);
|
||||
@ -1301,6 +1302,20 @@ namespace SettingsModelUnitTests
|
||||
VERIFY_ARE_EQUAL(SettingsLoadWarnings::MissingRequiredParameter, settings->Warnings().GetAt(3));
|
||||
}
|
||||
|
||||
void DeserializationTests::TestClampingOfStartupColumnAndViewProperties()
|
||||
{
|
||||
static constexpr std::string_view inputSettings{ R"({
|
||||
"initialCols" : 1000000,
|
||||
"initialRows" : -1000000,
|
||||
"profiles": [{ "name": "profile0" }]
|
||||
})" };
|
||||
|
||||
const auto settings = createSettings(inputSettings);
|
||||
|
||||
VERIFY_ARE_EQUAL(999, settings->GlobalSettings().InitialCols());
|
||||
VERIFY_ARE_EQUAL(1, settings->GlobalSettings().InitialRows());
|
||||
}
|
||||
|
||||
void DeserializationTests::TestTrailingCommas()
|
||||
{
|
||||
static constexpr std::string_view badSettings{ R"({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user