diff --git a/src/main/scala/com/sksamuel/scapegoat/io/HtmlReportWriter.scala b/src/main/scala/com/sksamuel/scapegoat/io/HtmlReportWriter.scala index 9a4b10f3..cd809977 100644 --- a/src/main/scala/com/sksamuel/scapegoat/io/HtmlReportWriter.scala +++ b/src/main/scala/com/sksamuel/scapegoat/io/HtmlReportWriter.scala @@ -2,7 +2,7 @@ package com.sksamuel.scapegoat.io import scala.xml.{Elem, Unparsed, XML} -import com.sksamuel.scapegoat.{Feedback, Levels} +import com.sksamuel.scapegoat.{Feedback, Levels, Warning} /** * @author @@ -100,11 +100,11 @@ object HtmlReportWriter extends ReportWriter { {reporter.warnings(Levels.Warning).size.toString} Infos {reporter.warnings(Levels.Info).size.toString} - {warnings(reporter)} + {warnings(reporter.warningsWithMinimalLevel)} - private def warnings(reporter: Feedback): Seq[Elem] = { - reporter.warningsWithMinimalLevel.map { warning => + private[io] def warnings(warnings: Seq[Warning]): Seq[Elem] = { + warnings.map { warning => val source = warning.sourceFileNormalized + ":" + warning.line
@@ -123,7 +123,7 @@ object HtmlReportWriter extends ReportWriter {
- {decorateCode(warning.explanation)} + {decorateCode(warning.explanation.replace("<", "<").replace(">", ">"))}
{ warning.snippet match { case None => diff --git a/src/test/scala/com/sksamuel/scapegoat/io/HtmlReportWriterTest.scala b/src/test/scala/com/sksamuel/scapegoat/io/HtmlReportWriterTest.scala new file mode 100644 index 00000000..9fbc4e27 --- /dev/null +++ b/src/test/scala/com/sksamuel/scapegoat/io/HtmlReportWriterTest.scala @@ -0,0 +1,44 @@ +package com.sksamuel.scapegoat.io + +import com.sksamuel.scapegoat.{Levels, Warning} +import org.scalatest.freespec.AnyFreeSpec +import org.scalatest.matchers.should.Matchers + +class HtmlReportWriterTest extends AnyFreeSpec with Matchers { + + "HtmlReportWriter" - { + "should escape angle brackets" in { + val warnings = Seq( + Warning( + "Pointless type bounds", + 13, + Levels.Error, + "/home/johnnei/git/scapegoat/src/main/scala/com/sksamuel/File.scala", + "com.sksamuel.File.scala", + None, + explanation = "Finds type bounds of the form `A <: Any` or `A >: Nothing`.", + inspection = "com.sksamuel.scapegoat.inspections.inference.PointlessTypeBounds" + ) + ) + + val escapedReport = Seq( +
+
+ com.sksamuel.File.scala:13 +
+
+ Error Pointless type bounds  + com.sksamuel.scapegoat.inspections.inference.PointlessTypeBounds + +
+
+ Finds type bounds of the form A <: Any or A >: Nothing. +
+
+ ) + + val report = HtmlReportWriter.warnings(warnings) + report.toString() shouldEqual escapedReport.toString() + } + } +}