diff --git a/scripts/src/java/org/oppia/android/scripts/coverage/reporter/CoverageReporter.kt b/scripts/src/java/org/oppia/android/scripts/coverage/reporter/CoverageReporter.kt
index 31763392945..f447a58c256 100644
--- a/scripts/src/java/org/oppia/android/scripts/coverage/reporter/CoverageReporter.kt
+++ b/scripts/src/java/org/oppia/android/scripts/coverage/reporter/CoverageReporter.kt
@@ -1,5 +1,6 @@
package org.oppia.android.scripts.coverage.reporter
+import com.google.common.html.HtmlEscapers
import org.oppia.android.scripts.proto.Coverage
import org.oppia.android.scripts.proto.CoverageReport
import org.oppia.android.scripts.proto.CoverageReportContainer
@@ -277,7 +278,7 @@ class CoverageReporter(
"""
${lineNumber.toString().padStart(4, ' ')} |
- $line |
+ ${HtmlEscapers.htmlEscaper().escape(line)} |
""".trimIndent()
)
diff --git a/scripts/src/javatests/org/oppia/android/scripts/coverage/RunCoverageTest.kt b/scripts/src/javatests/org/oppia/android/scripts/coverage/RunCoverageTest.kt
index 7ef0183f00d..3d28a816c7d 100644
--- a/scripts/src/javatests/org/oppia/android/scripts/coverage/RunCoverageTest.kt
+++ b/scripts/src/javatests/org/oppia/android/scripts/coverage/RunCoverageTest.kt
@@ -317,7 +317,13 @@ class RunCoverageTest {
val expectedResult = getExpectedHtmlText(kotlinFilePath)
- assertThat(readHtmlReport(kotlinFilePath)).isEqualTo(expectedResult)
+ val unescapedHtmlReport = readHtmlReport(kotlinFilePath)
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+
+ assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}
@Test
@@ -342,7 +348,13 @@ class RunCoverageTest {
val expectedResult = getExpectedHtmlText(sourceFilePath)
- assertThat(readHtmlReport(sourceFilePath)).isEqualTo(expectedResult)
+ val unescapedHtmlReport = readHtmlReport(sourceFilePath)
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+
+ assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}
@Test
@@ -541,7 +553,13 @@ class RunCoverageTest {
val expectedResult = getExpectedHtmlText(filePath)
- assertThat(readHtmlReport(filePath)).isEqualTo(expectedResult)
+ val unescapedHtmlReport = readHtmlReport(filePath)
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+
+ assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}
@Test
@@ -1880,10 +1898,20 @@ class RunCoverageTest {
).execute()
val expectedResult1 = getExpectedHtmlText(filePathList.get(0))
- assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult1)
+ val unescapedHtmlReport1 = readHtmlReport(filePathList.get(0))
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+ assertThat(unescapedHtmlReport1).isEqualTo(expectedResult1)
val expectedResult2 = getExpectedHtmlText(filePathList.get(1))
- assertThat(readHtmlReport(filePathList.get(1))).isEqualTo(expectedResult2)
+ val unescapedHtmlReport2 = readHtmlReport(filePathList.get(1))
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+ assertThat(unescapedHtmlReport2).isEqualTo(expectedResult2)
}
@Test
@@ -1910,7 +1938,13 @@ class RunCoverageTest {
val expectedResult = getExpectedHtmlText(filePathList.get(0))
- assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
+ val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+
+ assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}
@Test
@@ -1937,7 +1971,13 @@ class RunCoverageTest {
val expectedResult = getExpectedHtmlText(filePathList.get(0))
- assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
+ val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+
+ assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}
@Test
@@ -1964,7 +2004,13 @@ class RunCoverageTest {
val expectedResult = getExpectedHtmlText(filePathList.get(0))
- assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
+ val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+
+ assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}
@Test
@@ -2009,7 +2055,13 @@ class RunCoverageTest {
val expectedResult = getExpectedHtmlText(filePathList.get(0))
- assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
+ val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+
+ assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}
@Test
@@ -2036,7 +2088,13 @@ class RunCoverageTest {
val expectedResult = getExpectedHtmlText(filePathList.get(0))
- assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
+ val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
+ .replace(""", "\"")
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+
+ assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}
@Test
@@ -2262,7 +2320,13 @@ class RunCoverageTest {