Skip to content

Commit

Permalink
Dyn 4715 package name special characters (#12802)
Browse files Browse the repository at this point in the history
* Preventing Special Characters in the Publish Package

* Updating Warning name and comments

* Updating the SpecialAndInvalidCharacters function to the .Net Library

* Refactoring the SpecialAndInvalidCharacters to single line

* Updating the accesibility level of the SpecialAndInvalidCharacters function

* Using the SpecialAndInvalidCharacters as a static property

* Restoring the function ContainsSpecialCharacters for testing purpose

* Moving the place of the SpecialAndInvalidCharacters

* Removing the InvalidCharacters static property
  • Loading branch information
jesusalvino authored Apr 20, 2022
1 parent 2f7d6c6 commit a496720
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 44 deletions.
8 changes: 5 additions & 3 deletions src/DynamoCore/Search/SearchDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Diagnostics;
using Dynamo.Configuration;
using DynamoUtilities;

namespace Dynamo.Search
{
Expand Down Expand Up @@ -321,13 +322,14 @@ private static Dictionary<V, double> MatchWithSubset(Dictionary<V,double> search
private static string[] SplitOnWhiteSpace(string s)
{
return s.Split(null);
}
}

private static bool ContainsSpecialCharacters(string element)
{
return element.Contains("*") || element.Contains(".") || element.Contains(" ")
|| element.Contains("\\");
Char[] invalidCharacters = PathHelper.SpecialAndInvalidCharacters();
return (!string.IsNullOrEmpty(element) && element.IndexOfAny(invalidCharacters) >= 0);
}

#endregion

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ Next assemblies were loaded several times:
{0}</value>
</data>
<data name="PackageNameCannotContainTheseCharacters" xml:space="preserve">
<value>The name of the package cannot contain /,\, or *.</value>
<value>The name of the package cannot contain</value>
<comment>ErrorString</comment>
</data>
<data name="PackageNeedAtLeastOneFile" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ If the toggle is off custom packages that are not already loaded will load once
<comment>ErrorString</comment>
</data>
<data name="PackageNameCannotContainTheseCharacters" xml:space="preserve">
<value>The name of the package cannot contain /,\, or *.</value>
<value>The name of the package cannot contain</value>
<comment>ErrorString</comment>
</data>
<data name="PackageNeedAtLeastOneFile" xml:space="preserve">
Expand Down
156 changes: 122 additions & 34 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,40 @@
<Setter Property="Background" Value="#343434" />
</Style>

<!-- Generic Dynamo ToolTip -->
<Style x:Key="GenericToolTipLight" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="MaxWidth" Value="300" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Grid x:Name="PopupGrid">
<Grid x:Name="ShadowBackground" Background="Transparent">
<Path Margin="5 0 0 0" Width="20" Height="6" HorizontalAlignment="Left" VerticalAlignment="Top" Data="M0,6 L6,0 12,6Z" Stroke="Gray" Fill="White" Stretch="None" />
<Border BorderThickness="1 0 1 1" CornerRadius="3" Margin="0 5 7 7" BorderBrush="#999999" Background="white" Padding="10,8">
<ContentPresenter/>
</Border>
<Border BorderThickness="0 1 0 0" CornerRadius="0 0 3 0" Margin="16 5 9 0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="7" BorderBrush="#999999" />
<Border BorderThickness="0 1 0 0" CornerRadius="3 0 0 0" Margin="0 5 0 0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="7" Width="6" BorderBrush="#999999" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="ContentPresenter">
<Style.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementRegular}" />
<Setter Property="FontSize" Value="12px" />
<Setter Property="Foreground" Value="#232323" />
</Style>
</Style.Resources>
</Style>
</Style.Resources>
</Style>

<Image x:Key="ComboDownIcon_normal" Source="pack://application:,,,/DynamoCoreWpf;component/UI/Images/tick_selected.png" />

<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
Expand Down Expand Up @@ -723,6 +757,94 @@
</Setter>
</Style>

<Style x:Key="InputStyleWithIcon" TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,0,0,12" />
<Setter Property="MinWidth" Value="62px" />
<Setter Property="CaretBrush" Value="{StaticResource PrimaryCharcoal200Brush}" />
<Setter Property="Padding" Value="10,12,10,8"/>
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementRegular}"/>
<Setter Property="FontSize" Value="12px" />
<Setter Property="Foreground" Value="{StaticResource PrimaryCharcoal200Brush}"/>
<Setter Property="TextWrapping" Value="Wrap"/>

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="25" />
</Grid.ColumnDefinitions>
<Border Grid.Row="0"
Grid.ColumnSpan="2"
Background="#353535"
BorderBrush="Transparent"
BorderThickness="1"
/>
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center"/>
<Label x:Name="WaterMarkLabel"
Grid.Row="0"
Padding="13,13,10,8"
Content="{TemplateBinding Tag}"
VerticalAlignment="Center"
Visibility="Collapsed"
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="12px"
Foreground="{StaticResource PrimaryCharcoal200Brush}"
IsHitTestVisible="False"
Opacity="0.5"/>
<!-- This is the Canvas for the exclamation mark appearing when the Style that the user is trying to insert already exists -->
<Canvas Grid.Column="1" Margin="0,5,5,0"
Visibility="{Binding Path=IsWarningEnabled, Converter={StaticResource BooleanToVisibilityConverter}}">
<Canvas.ToolTip>
<ToolTip Content="{Binding CurrentWarningMessage}" Style="{StaticResource GenericToolTipLight}"/>
</Canvas.ToolTip>
<Path Fill="#FAA21B">
<Path.Data>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure IsClosed="True" StartPoint="10,5">
<PathFigure.Segments>
<PathSegmentCollection>
<LineSegment Point="18,20" />
<LineSegment Point="2,20" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<GeometryGroup FillRule="EvenOdd">
<EllipseGeometry Center="10,18" RadiusX="1.5" RadiusY="1.5"/>
<RectangleGeometry Rect="8.5,8.5,3,7.5"/>
</GeometryGroup>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Path.Data>
</Path>
</Canvas>
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Text" Value=""/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" TargetName="WaterMarkLabel" Value="Visible"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{StaticResource PrimaryCharcoal200Brush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="LabelStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementBold}" />
<Setter Property="FontWeight" Value="Bold" />
Expand Down Expand Up @@ -1899,40 +2021,6 @@
</Setter>
</Style>

<!-- Generic Dynamo ToolTip -->
<Style x:Key="GenericToolTipLight" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="MaxWidth" Value="300" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Grid x:Name="PopupGrid">
<Grid x:Name="ShadowBackground" Background="Transparent">
<Path Margin="5 0 0 0" Width="20" Height="6" HorizontalAlignment="Left" VerticalAlignment="Top" Data="M0,6 L6,0 12,6Z" Stroke="Gray" Fill="White" Stretch="None" />
<Border BorderThickness="1 0 1 1" CornerRadius="3" Margin="0 5 7 7" BorderBrush="#999999" Background="white" Padding="10,8">
<ContentPresenter/>
</Border>
<Border BorderThickness="0 1 0 0" CornerRadius="0 0 3 0" Margin="16 5 9 0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="7" BorderBrush="#999999" />
<Border BorderThickness="0 1 0 0" CornerRadius="3 0 0 0" Margin="0 5 0 0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="7" Width="6" BorderBrush="#999999" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="ContentPresenter">
<Style.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementRegular}" />
<Setter Property="FontSize" Value="12px" />
<Setter Property="Foreground" Value="#232323" />
</Style>
</Style.Resources>
</Style>
</Style.Resources>
</Style>

<Style x:Key="StartPageListBox" TargetType="ListBox">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Dynamo.ViewModels;
using Dynamo.Wpf.Properties;
using Dynamo.Wpf.Utilities;
using DynamoUtilities;
using Greg.Requests;
using Microsoft.Practices.Prism.Commands;
using PythonNodeModels;
Expand Down Expand Up @@ -696,6 +697,40 @@ public PackageUploadRequestBody BaseVersionHeader
}
}

private bool isWarningEnabled;
/// <summary>
/// This flag will be in true when the package name is invalid
/// </summary>
public bool IsWarningEnabled
{
get
{
return isWarningEnabled;
}
set
{
isWarningEnabled = value;
RaisePropertyChanged(nameof(IsWarningEnabled));
}
}

private string currentWarningMessage;
/// <summary>
/// This property will hold the warning message that has to be shown in the warning icon next to the TextBox
/// </summary>
public string CurrentWarningMessage
{
get
{
return currentWarningMessage;
}
set
{
currentWarningMessage = value;
RaisePropertyChanged(nameof(CurrentWarningMessage));
}
}

#endregion

internal PublishPackageViewModel()
Expand Down Expand Up @@ -770,6 +805,7 @@ public PublishPackageViewModel( DynamoViewModel dynamoViewModel ) : this()
{
this.dynamoViewModel = dynamoViewModel;
KnownHosts = initializeHostSelections();
isWarningEnabled = false;
}

private void ClearAllEntries()
Expand Down Expand Up @@ -1723,11 +1759,16 @@ private bool CanPublishLocally()

private bool CheckPackageValidity()
{
if (Name.Contains(@"\") || Name.Contains(@"/") || Name.Contains(@"*"))
if (!string.IsNullOrEmpty(Name) && Name.IndexOfAny(PathHelper.SpecialAndInvalidCharacters()) >= 0)
{
ErrorString = Resources.PackageNameCannotContainTheseCharacters;
ErrorString = Resources.PackageNameCannotContainTheseCharacters + " " + new String(PathHelper.SpecialAndInvalidCharacters());
EnableInvalidNameWarningState(ErrorString);
return false;
}
else
{
IsWarningEnabled = false;
}

if (Name.Length < 3)
{
Expand Down Expand Up @@ -1777,6 +1818,15 @@ private bool CheckPackageValidity()

return true;
}
}

/// <summary>
/// This method will enable the warning icon next to the Package Name TextBox
/// </summary>
/// <param name="warningMessage">Message that will be displayed when the mouse is over the warning</param>
internal void EnableInvalidNameWarningState(string warningMessage)
{
CurrentWarningMessage = warningMessage;
IsWarningEnabled = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" />
</ResourceDictionary.MergedDictionaries>
<controls:EmptyStringToFalseConverter x:Key="EmptyStringToFalseConverter" />
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
<Grid Height="29px"
HorizontalAlignment="Stretch"
Expand Down Expand Up @@ -419,7 +420,7 @@
</TextBlock.ToolTip>
</TextBlock>
<TextBox Name="packageNameInput"
Style="{StaticResource InputStyle}"
Style="{StaticResource InputStyleWithIcon}"
Tag="{x:Static p:Resources.PublishPackageViewPackageNameWatermark}"
IsEnabled ="{Binding Path=CanEditName}"
Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoUtilities/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,11 @@ public static void FileInfoAtPath(string path, out bool fileExists, out string s
size = string.Empty;
}
}

internal static Char[] SpecialAndInvalidCharacters()
{
// Excluding white spaces and uncommon characters, only keeping the displayed in the Windows alert
return System.IO.Path.GetInvalidFileNameChars().Where(x => !char.IsWhiteSpace(x) && (int)x > 31).ToArray();
}
}
}

0 comments on commit a496720

Please sign in to comment.