Skip to content

Commit 1f4fb6a

Browse files
committed
#192, #209: Parsing of invalid Cobertura files
1 parent c1fa888 commit 1f4fb6a

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

src/Readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ CHANGELOG
6060

6161
4.0.12.0
6262

63-
* Fix: Issue #209: Added warning if Cobertura file is invalid
63+
* Fix: Issue #192, #209: Parsing of invalid Cobertura files
6464

6565
4.0.11.0
6666

src/ReportGenerator.Core/Parser/CoberturaParser.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ public override ParserResult Parse(XContainer report)
7070
var modules = report.Descendants("package")
7171
.ToArray();
7272

73-
if (modules.Length == 0)
74-
{
75-
if (report.Descendants("packages").Elements("class").Any())
76-
{
77-
Logger.Error(" " + Resources.ErrorInvalidCoberturaReport);
78-
}
79-
}
80-
8173
var assemblyNames = modules
8274
.Select(m => m.Attribute("name").Value)
8375
.Distinct()

src/ReportGenerator.Core/Parser/Preprocessing/CoberturaReportPreprocessor.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.IO;
22
using System.Linq;
33
using System.Xml.Linq;
4+
using Palmmedia.ReportGenerator.Core.Logging;
5+
using Palmmedia.ReportGenerator.Core.Properties;
46

57
namespace Palmmedia.ReportGenerator.Core.Parser.Preprocessing
68
{
@@ -9,12 +11,39 @@ namespace Palmmedia.ReportGenerator.Core.Parser.Preprocessing
911
/// </summary>
1012
internal class CoberturaReportPreprocessor
1113
{
14+
/// <summary>
15+
/// The Logger.
16+
/// </summary>
17+
private static readonly ILogger Logger = LoggerFactory.GetLogger(typeof(CoberturaReportPreprocessor));
18+
1219
/// <summary>
1320
/// Executes the preprocessing of the report.
1421
/// </summary>
1522
/// <param name="report">The report.</param>
1623
internal void Execute(XContainer report)
1724
{
25+
var modules = report.Descendants("package")
26+
.ToArray();
27+
28+
if (modules.Length == 0)
29+
{
30+
if (report.Descendants("packages").Elements("class").Any())
31+
{
32+
Logger.Error(" " + Resources.ErrorInvalidCoberturaReport);
33+
34+
// Fix malformed report files (See issues: #192, #209)
35+
foreach (var packagesElement in report.Descendants("packages").ToArray())
36+
{
37+
packagesElement.Name = "classes";
38+
39+
var parent = packagesElement.Parent;
40+
41+
packagesElement.Remove();
42+
parent.Add(new XElement("packages", new XElement("package", new XAttribute("name", "AutoGenerated"), packagesElement)));
43+
}
44+
}
45+
}
46+
1847
var sources = report.Descendants("sources")
1948
.Elements("source")
2049
.Select(s => s.Value)

src/ReportGenerator.Core/Reporting/Builders/Rendering/HtmlRenderer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,17 @@ private static string GetClassReportFilename(string assemblyName, string classNa
12061206

12071207
if (!FileNameByClass.TryGetValue(key, out fileName))
12081208
{
1209-
string shortClassName = className.Substring(className.LastIndexOf('.') + 1);
1209+
string shortClassName = null;
1210+
1211+
if (className.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
1212+
{
1213+
shortClassName = className.Substring(0, className.LastIndexOf('.'));
1214+
}
1215+
else
1216+
{
1217+
shortClassName = className.Substring(className.LastIndexOf('.') + 1);
1218+
}
1219+
12101220
fileName = RendererBase.ReplaceInvalidPathChars(assemblyName + "_" + shortClassName) + ".htm";
12111221

12121222
if (fileName.Length > 100)

0 commit comments

Comments
 (0)