Skip to content

Commit

Permalink
Merge pull request #96 from AshleighAdams/more-unicode-fixes
Browse files Browse the repository at this point in the history
GitRepoInspector: Trim the response from git incase whitespace chars present
  • Loading branch information
AshleighAdams authored Jun 25, 2022
2 parents cc155d6 + f8a155e commit 0a98df5
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/Verlite.Core/GitRepoInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,41 @@ private static IReadOnlyList<Commit> ParseCommitObjectParents(string commitObj)
private UTF8Encoding Encoding { get; } = new(
encoderShouldEmitUTF8Identifier: false,
throwOnInvalidBytes: false);

private char[] WhitespaceChars { get; } = new[]
{
'\t',
'\v',
'\f',
'\r',
'\n',
' ',
'\u0085', // NEXT LINE
'\u00A0', // NBSP
'\u1680', // OGHAM SPACE MARK
'\u2000', // EN QUAD
'\u2001', // EM QUAD
'\u2002', // EN SPACE
'\u2003', // EM SPACE
'\u2004', // THREE-PER-EM SPACE
'\u2005', // FOUR-PER-EM SPACE
'\u2006', // SIX-PER-EM SPACE
'\u2007', // FIGURE SPACE
'\u2008', // PUNCTUATION SPACE
'\u2009', // THIN SPACE
'\u200A', // HAIR SPACE
'\u2028', // LINE SEPARATOR
'\u2029', // PARAGRAPH SEPARATOR
'\u202F', // NARROW NBSP
'\u205F', // MEDIUM MATHEMATICAL SPACE
'\u3000', // IDEOGRAPHIC SPACE
'\u180E', // MONGOLIAN VOWEL SEPARATOR
'\u200B', // ZERO WIDTH SPACE
'\u200C', // ZERO WIDTH NON-JOINER
'\u200D', // ZERO WIDTH JOINER
'\u2060', // WORD JOINER
'\uFEFF', // ZERO WIDTH NON-BREAKING SPACE
};
private async Task<string?> CatFile(string type, string id)
{
await catFileSemaphore.WaitAsync();
Expand Down Expand Up @@ -182,7 +217,7 @@ private static IReadOnlyList<Commit> ParseCommitObjectParents(string commitObj)
throw new UnknownGitException("The git cat-file process timed out.");

var result = await gotBack;
if (result != " missing")
if (result.Trim(WhitespaceChars) != "missing")
throw new UnknownGitException($"The git cat-file process returned unexpected output: {result}");
}

Expand All @@ -199,7 +234,7 @@ private static IReadOnlyList<Commit> ParseCommitObjectParents(string commitObj)

string line = await readLineTask;
Log?.Verbatim($"git cat-file > {line}");
string[] response = line.Split(' ');
string[] response = line.Trim(WhitespaceChars).Split(' ');


if (response[0] != id)
Expand Down

0 comments on commit 0a98df5

Please sign in to comment.