Skip to content

Commit

Permalink
Fix guid scrubber not handling guids between letters and/or numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Crown0815 committed Oct 9, 2024
1 parent 40ba34f commit 0bebb41
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
173535ae-995b-4cc6-a74e-8cd4be57039ca
Guid_1a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
173535ae-995b-4cc6-a74e-8cd4be57039c1
Guid_11
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a173535ae-995b-4cc6-a74e-8cd4be57039ca
aGuid_1a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1173535ae-995b-4cc6-a74e-8cd4be57039c1
1Guid_11
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a173535ae-995b-4cc6-a74e-8cd4be57039c
aGuid_1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1173535ae-995b-4cc6-a74e-8cd4be57039c
1Guid_1
28 changes: 5 additions & 23 deletions src/Verify/Serialization/Scrubbers/GuidScrubber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ public static void ReplaceGuids(StringBuilder builder, Counter counter)
var value = builder.ToString().AsSpan();

var builderIndex = 0;
for (var index = 0; index <= value.Length; index++)
for (var index = 0; index <= value.Length - 36; index++)
{
var end = index + 36;
if (end > value.Length)
{
return;
}

if ((index == 0 || !IsInvalidStartingChar(value[index - 1])) &&
(end == value.Length || !IsInvalidEndingChar(value[end])))
if (value[index + 8] == '-' &&
value[index + 13] == '-' &&
value[index + 18] == '-' &&
value[index + 23] == '-')
{
var slice = value.Slice(index, 36);
if (!slice.ContainsNewline() && TryParse(slice, out var guid))
Expand All @@ -49,18 +45,4 @@ static bool TryParse(CharSpan slice, out Guid guid) =>
#else
Guid.TryParseExact(slice.ToString(), "D", out guid);
#endif

static bool IsInvalidEndingChar(char ch) =>
IsInvalidChar(ch) &&
ch != '}' &&
ch != ')';

static bool IsInvalidChar(char ch) =>
char.IsLetter(ch) ||
char.IsNumber(ch);

static bool IsInvalidStartingChar(char ch) =>
IsInvalidChar(ch) &&
ch != '{' &&
ch != '(';
}

0 comments on commit 0bebb41

Please sign in to comment.