Skip to content

Commit 9a9049b

Browse files
committed
fix validate method for surrogate pairs and update test; remove whitelist tests
1 parent 1a7db8d commit 9a9049b

File tree

2 files changed

+11
-65
lines changed

2 files changed

+11
-65
lines changed

src/StorageSync/StorageSync.Test/UnitTests/FilenamesCharactersValidationTest.cs

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -78,67 +78,6 @@ public void ItReturnsErrorOnFileWithInvalidCodePoint()
7878
Assert.StrictEqual<Result>(Result.Fail, validationResult.Result);
7979
}
8080

81-
/// <summary>
82-
/// Defines the test method ItReturnsErrorWhenCodePointIsInBoundsOfRange.
83-
/// </summary>
84-
[Fact]
85-
[Trait(Category.AcceptanceType, Category.CheckIn)]
86-
public void ItReturnsErrorWhenCodePointIsInBoundsOfRange()
87-
{
88-
var configurationMockFactory = new Moq.Mock<IConfiguration>();
89-
List<Configuration.CodePointRange> whitelist = new List<Configuration.CodePointRange> {
90-
new Configuration.CodePointRange {
91-
Start = 0x00,
92-
End = 0x77 // x - 1
93-
},
94-
new Configuration.CodePointRange {
95-
Start = 0x7B, // z + 1
96-
End = 0x10FFFF
97-
},
98-
};
99-
configurationMockFactory.Setup(configuration => configuration.BlacklistOfCodePoints()).Returns(new List<int>());
100-
FilenamesCharactersValidation validation = new FilenamesCharactersValidation(configurationMockFactory.Object);
101-
102-
var fileInfoMockFactory = new Moq.Mock<IFileInfo>();
103-
fileInfoMockFactory.SetupGet(fileInfo => fileInfo.Name).Returns("AAAxAAAzAAA");
104-
IValidationResult validationResult = validation.Validate(fileInfoMockFactory.Object);
105-
106-
Assert.StrictEqual<Result>(Result.Fail, validationResult.Result);
107-
Assert.True(validationResult.Positions.Count == 2, $"Unexpected number of error positions");
108-
Assert.True(validationResult.Positions[0] == 4, $"Unexpected position of first error");
109-
Assert.True(validationResult.Positions[1] == 8, $"Unexpected position of second error");
110-
}
111-
112-
/// <summary>
113-
/// Defines the test method ItReturnsErrorWhenCodePointIsInMiddleOfRange.
114-
/// </summary>
115-
[Fact]
116-
[Trait(Category.AcceptanceType, Category.CheckIn)]
117-
public void ItReturnsErrorWhenCodePointIsInMiddleOfRange()
118-
{
119-
var configurationMockFactory = new Moq.Mock<IConfiguration>();
120-
List<Configuration.CodePointRange> whitelist = new List<Configuration.CodePointRange> {
121-
new Configuration.CodePointRange {
122-
Start = 0x00,
123-
End = 0x77 // x - 1
124-
},
125-
new Configuration.CodePointRange {
126-
Start = 0x7B, // z + 1
127-
End = 0x10FFFF
128-
},
129-
};
130-
131-
configurationMockFactory.Setup(configuration => configuration.BlacklistOfCodePoints()).Returns(new List<int>());
132-
FilenamesCharactersValidation validation = new FilenamesCharactersValidation(configurationMockFactory.Object);
133-
134-
var fileInfoMockFactory = new Moq.Mock<IFileInfo>();
135-
fileInfoMockFactory.SetupGet(fileInfo => fileInfo.Name).Returns("AAAyAAA");
136-
IValidationResult validationResult = validation.Validate(fileInfoMockFactory.Object);
137-
138-
Assert.StrictEqual<Result>(Result.Fail, validationResult.Result);
139-
Assert.True(validationResult.Positions.Count == 1, $"Unexpected number of error positions");
140-
Assert.True(validationResult.Positions[0] == 4, $"Unexpected position of first error");
141-
}
14281

14382
/// <summary>
14483
/// Defines the test method TestWithRealConfigReturnsSuccessForValidSurrogateCodePoint.
@@ -171,16 +110,20 @@ public void TestWithRealConfigReturnsErrorForInvalidCodePoint()
171110
fileInfoMockFactory.SetupGet(fileInfo => fileInfo.Name).Returns(new string(new char[] {
172111
'a',
173112
(char)0xD834, (char)0xDD1E, // valid surrogate pair
174-
(char)0xFFF0, // invalid codepoint
113+
(char)0xD834, 'a', // invalid surrogate pair,
114+
'a', (char)0xDD1E, // invalid surrogate pair,
115+
(char)0xD834, 'a', // invalid surrogate pair,
175116
'z',
176117
(char)0x007C // blacklisted codepoint
177118
}));
178119
IValidationResult validationResult = validation.Validate(fileInfoMockFactory.Object);
179120

180121
Assert.StrictEqual<Result>(Result.Fail, validationResult.Result);
181-
Assert.True(validationResult.Positions.Count == 2, $"Unexpected number of error positions");
182-
Assert.True(validationResult.Positions[0] == 3, $"Unexpected position of first error");
183-
Assert.True(validationResult.Positions[1] == 5, $"Unexpected position of second error");
122+
Assert.True(validationResult.Positions.Count == 4, $"Unexpected number of error positions");
123+
Assert.True(validationResult.Positions[0] == 4, $"Unexpected position of first error");
124+
Assert.True(validationResult.Positions[1] == 7, $"Unexpected position of second error");
125+
Assert.True(validationResult.Positions[2] == 8, $"Unexpected position of third error");
126+
Assert.True(validationResult.Positions[3] == 11, $"Unexpected position of fourth error");
184127
}
185128

186129
}

src/StorageSync/StorageSync/Validations/NamespaceValidations/FilenamesCharactersValidation.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private IValidationResult ValidateInternal(INamedObjectInfo node, bool isDirecto
122122
}
123123
else if (char.IsHighSurrogate(prevChar) && !char.IsLowSurrogate(name[i]))
124124
{
125+
--codepointIndex;
125126
codePoint = name[i];
126127
message = $"Invalid hight surrogate char found in the file name at location {i + 1}";
127128
}
@@ -147,6 +148,8 @@ private IValidationResult ValidateInternal(INamedObjectInfo node, bool isDirecto
147148
positions.Add(codepointIndex + 1);
148149
}
149150

151+
codepointIndex = i;
152+
150153
if (!string.IsNullOrEmpty(message))
151154
{
152155
Trace.TraceInformation(message);

0 commit comments

Comments
 (0)