Skip to content

Commit 9e66e34

Browse files
committed
fix crash on invalid cref
1 parent 44650b7 commit 9e66e34

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/InheritDoc/InheritDoc.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>2.0.1</VersionPrefix>
4+
<VersionPrefix>2.0.2</VersionPrefix>
55
<TargetFrameworks>netstandard2.0</TargetFrameworks>
66
</PropertyGroup>
77

@@ -21,14 +21,14 @@
2121

2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.0.461" />
24-
<PackageReference Include="Mono.Cecil" Version="0.11.5" PrivateAssets="all" />
24+
<PackageReference Include="Mono.Cecil" Version="0.11.6" PrivateAssets="all" />
2525
<!-- these are for use in the test project, downloaded here to avoid version conflicts when building tests -->
2626
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[7.0.0]" />
2727
<PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net48" Version="[1.0.0]" />
2828
</ItemGroup>
2929

3030
<Target Name="VerifyPackDependencies" BeforeTargets="GenerateNuspec">
31-
<Error Condition="@(None->WithMetadataValue('Pack', 'true')->WithMetadataValue('Filename', 'Mono.Cecil')->Count()) != 1" Text="Dependencies were not present for pack. Start build again." />
31+
<Error Condition="@(None-&gt;WithMetadataValue('Pack', 'true')-&gt;WithMetadataValue('Filename', 'Mono.Cecil')-&gt;Count()) != 1" Text="Dependencies were not present for pack. Start build again." />
3232
</Target>
3333

3434
</Project>

src/InheritDoc/InheritDocProcessor.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static XDocument loadDoc(string path)
9494
;
9595

9696
var docMap = generateDocMap(types, docMembers, trimLevel, logger);
97-
var docCref = docMembers.Elements(DocElementNames.Member).Where(m => !m.HasAttribute(DocAttributeNames._trimmed)).Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(c => !string.IsNullOrWhiteSpace(c));
97+
var docCref = docMembers.Elements(DocElementNames.Member).Where(m => !m.HasAttribute(DocAttributeNames._trimmed)).Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(isValidCref);
9898
var asmTypes = types.Select(t => t.GetDocID()).ToHashSet();
9999

100100
var refCref = docMap.Values.SelectMany(v => v.Select(l => l.Cref)).Concat(docCref).Where(c => !asmTypes.Contains(getTypeIDFromDocID(c))).ToHashSet();
@@ -171,7 +171,7 @@ private static IDictionary<string, IEnumerable<DocMatch>> generateDocMap(IList<T
171171
{
172172
logger.Write(ILogger.Severity.Diag, "Processing DocID: " + typeID);
173173

174-
var crefs = typeDocs.Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
174+
var crefs = typeDocs.Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(isValidCref).ToList();
175175
var dml = new List<DocMatch>();
176176
docMap.Add(typeID, dml);
177177

@@ -267,7 +267,7 @@ private static IDictionary<string, IEnumerable<DocMatch>> generateDocMap(IList<T
267267
logger.Write(ILogger.Severity.Diag, "Processing DocID: " + memID);
268268

269269
var bases = (om is not null ? (new[] { om }) : []).Concat(m.GetBaseCandidates()).ToList();
270-
var crefs = methDocs.Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(c => !string.IsNullOrWhiteSpace(c)).ToHashSet();
270+
var crefs = methDocs.Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(isValidCref).ToHashSet();
271271
var dml = new List<DocMatch>();
272272

273273
foreach (var (bm, cref) in bases.SelectMany(bm => bm.GetDocID().Select(d => (bm, d))))
@@ -555,6 +555,8 @@ static XDocument getRefDocs(IReadOnlyCollection<string> refAssemblies, IReadOnly
555555
}
556556
}
557557

558+
private static bool isValidCref(string cref) => cref is { Length: > 2 } && cref[0] is not '!' && (cref[0] is 'T' || cref.IndexOf('.', 2) > 0);
559+
558560
private static string getTypeIDFromDocID(string docID)
559561
{
560562
if (docID[0] == 'T')

tests/InheritDoc.Test/InheritDoc.Test.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
11-
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
12-
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
12+
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

0 commit comments

Comments
 (0)