Skip to content

Commit b278629

Browse files
Merge pull request #684 from Sitecore/feature/676-SIM_is_crashed_when_typing_an_Illegal_character_into_the_Site_name_field_during_installation
#676 Prevent using of invalid file name chars in the site name
2 parents 0d8d227 + 7afd1cb commit b278629

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/SIM.Tool.Windows/UserControls/Install/Instance9Details.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<ComboBox Grid.Row="3" Grid.Column="1" Name="ProductRevision" DisplayMemberPath="RevisionAndLabel" SelectionChanged="ProductRevisionChanged" />
3535

3636
<TextBlock Grid.Row="0" Grid.Column="3" Text="Site Name: " VerticalAlignment="Center" HorizontalAlignment="Left" Width="77" Grid.RowSpan="2" Height="16" Margin="0,6" Grid.ColumnSpan="3" />
37-
<TextBox Grid.Row="0" Grid.Column="5" Name="InstanceName" Text="{Binding ElementName=ProductRevision, Path=SelectedValue, Converter={x:Static converters:Product._DefaultInstanceName}, Mode=OneWay}" Grid.RowSpan="2" />
37+
<TextBox Grid.Row="0" Grid.Column="5" Name="InstanceName" Text="{Binding ElementName=ProductRevision, Path=SelectedValue, Converter={x:Static converters:Product._DefaultInstanceName}, Mode=OneWay}" Grid.RowSpan="2" PreviewTextInput="InstanceName_PreviewTextInput" />
3838

3939
<TextBlock Grid.Column="3" Grid.Row="2" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" Width="30" Margin="0,5" Height="16"><Run Text="Solr:"/></TextBlock>
4040
<Button Grid.Column="4" Grid.Row="2" Content="+" Margin="0,3,0,2" Click="AddSolr_Click" HorizontalAlignment="Right" Width="23" />

src/SIM.Tool.Windows/UserControls/Install/Instance9Details.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public partial class Instance9Details : IWizardStep, IFlowControl
4444
private Window owner;
4545
private InstallWizardArgs _InstallParameters = null;
4646
private IEnumerable<Product> _StandaloneProducts;
47+
private char[] _InvalidChars;
4748

4849
// According to the following document the maximum length for a path in Windows systems is defined as 260 characters:
4950
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
@@ -57,6 +58,7 @@ public partial class Instance9Details : IWizardStep, IFlowControl
5758
public Instance9Details()
5859
{
5960
InitializeComponent();
61+
_InvalidChars = Path.GetInvalidFileNameChars();
6062
}
6163

6264
#endregion
@@ -762,5 +764,17 @@ private void AddSolr_Click(object sender, RoutedEventArgs e)
762764
this.Solrs.SelectedItem = solr;
763765
}
764766
}
767+
768+
private void InstanceName_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
769+
{
770+
if (e.Text.Any(c => _InvalidChars.Contains(c)))
771+
{
772+
WindowHelper.ShowMessage($"The enetered '{e.Text}' character is invalid for the site name.",
773+
messageBoxImage: MessageBoxImage.Warning,
774+
messageBoxButton: MessageBoxButton.OK
775+
);
776+
e.Handled = true;
777+
}
778+
}
765779
}
766780
}

0 commit comments

Comments
 (0)