Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
EnsureValidDataType should reject whitespaces in DataTypeAttribute.Cu…
Browse files Browse the repository at this point in the history
…stomDataType property because it is mandatory and it does not make sense that the property is whitespaces. (#14845)

Modify Ctor_String(string customDataType) test to validate whitespaces adding new InlineData.

Fix #4465
  • Loading branch information
sparraguerra authored and karelz committed Jan 12, 2017
1 parent 52b55d4 commit 78bce12
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override bool IsValid(object value)
/// <exception cref="InvalidOperationException"> is thrown if the current attribute is ill-formed.</exception>
private void EnsureValidDataType()
{
if (DataType == DataType.Custom && string.IsNullOrEmpty(CustomDataType))
if (DataType == DataType.Custom && string.IsNullOrWhiteSpace(CustomDataType))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
SR.DataTypeAttribute_EmptyDataTypeString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ public static void GetDataTypeName_InvalidDataType_ThrowsIndexOutOfRangeExceptio
[Theory]
[InlineData("CustomValue")]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public static void Ctor_String(string customDataType)
{
DataTypeAttribute attribute = new DataTypeAttribute(customDataType);
Assert.Equal(DataType.Custom, attribute.DataType);
Assert.Equal(customDataType, attribute.CustomDataType);

if (string.IsNullOrEmpty(customDataType))
if (string.IsNullOrWhiteSpace(customDataType))
{
Assert.Throws<InvalidOperationException>(() => attribute.GetDataTypeName());
Assert.Throws<InvalidOperationException>(() => attribute.Validate(new object(), s_testValidationContext));
Expand Down

0 comments on commit 78bce12

Please sign in to comment.