Skip to content

Commit 7d82a7f

Browse files
fix crash for absolute paths
1 parent 1e46143 commit 7d82a7f

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

CodeQualityToGitlab/SarifConverters/Converter1.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static string GetPath(string? pathRoot, LocationVersionOne begin)
8484
return NormalizeSeparators(begin.ResultFile.Uri.LocalPath.Replace(@"\\", @"\"));
8585
}
8686

87-
var uri = new Uri(pathRoot);
87+
var uri = GetUri(pathRoot);
8888
var absolutePath = begin.ResultFile.Uri.LocalPath;
8989
var rootPath = uri.LocalPath;
9090

@@ -96,6 +96,16 @@ private static string GetPath(string? pathRoot, LocationVersionOne begin)
9696
return NormalizeSeparators(begin.ResultFile.Uri.MakeRelativeUri(uri).ToString());
9797
}
9898

99+
private static Uri GetUri(string pathRoot)
100+
{
101+
if (Path.IsPathRooted(pathRoot))
102+
{
103+
return new(new Uri("file://"),pathRoot);
104+
}
105+
106+
return new(pathRoot);
107+
}
108+
99109
private static Severity GetSeverity(ResultLevelVersionOne resultLevel)
100110
{
101111
return resultLevel switch

CodeQualityToGitlab/Transform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private static void Process(
2828
)
2929
{
3030
Matcher matcher = new();
31-
matcher.AddIncludePatterns(new[] { roslynatorGlob });
31+
matcher.AddIncludePatterns([roslynatorGlob]);
3232

3333
const string searchDirectory = ".";
3434

Test/TestTransform.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ namespace Test;
77

88
public class TestTransform
99
{
10+
private static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions
11+
{
12+
WriteIndented = true,
13+
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
14+
Converters = { new JsonStringEnumConverter() }
15+
};
16+
1017
[Fact]
1118
public void TestTransformAllWorks()
1219
{
1320
var target = new FileInfo(Path.GetTempFileName());
1421

1522
Transform.TransformAll("**/**.sarif.json", "**/*roslynator.xml", target, null, true);
1623

17-
var options = new JsonSerializerOptions
18-
{
19-
WriteIndented = true,
20-
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
21-
Converters = { new JsonStringEnumConverter() }
22-
};
24+
var options = JsonSerializerOptions;
2325

2426
using var r = new StreamReader(target.FullName);
2527
var json = r.ReadToEnd();
@@ -33,14 +35,9 @@ public void TestTransformCreatesExpectedPath()
3335
{
3436
var target = new FileInfo(Path.GetTempFileName());
3537

36-
Transform.TransformAll("codeanalysis.sarif4.json", "", target, null, true);
38+
Transform.TransformAll("codeanalysis.sarif4.json", "", target, @"/builds/39753701/backend", true);
3739

38-
var options = new JsonSerializerOptions
39-
{
40-
WriteIndented = true,
41-
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
42-
Converters = { new JsonStringEnumConverter() }
43-
};
40+
var options = JsonSerializerOptions;
4441

4542
using var r = new StreamReader(target.FullName);
4643
var json = r.ReadToEnd();

0 commit comments

Comments
 (0)