@@ -23,6 +23,8 @@ import javax.servlet.http.HttpServletRequest
2323import scala .collection .mutable .{Buffer , HashMap , ListBuffer }
2424import scala .xml .{Node , NodeSeq , Unparsed , Utility }
2525
26+ import org .apache .commons .lang3 .StringEscapeUtils
27+
2628import org .apache .spark .JobExecutionStatus
2729import org .apache .spark .scheduler .StageInfo
2830import org .apache .spark .ui .{ToolTips , UIUtils , WebUIPage }
@@ -63,9 +65,10 @@ private[ui] class JobPage(parent: JobsTab) extends WebUIPage("job") {
6365 val submissionTime = stage.submissionTime.get
6466 val completionTime = stage.completionTime.getOrElse(System .currentTimeMillis())
6567
66- // The timeline library treats contents as HTML, so we have to escape them; for the
67- // data-title attribute string we have to escape them twice since that's in a string.
68+ // The timeline library treats contents as HTML, so we have to escape them. We need to add
69+ // extra layers of escaping in order to embed this in a Javascript string literal .
6870 val escapedName = Utility .escape(name)
71+ val jsEscapedName = StringEscapeUtils .escapeEcmaScript(escapedName)
6972 s """
7073 |{
7174 | 'className': 'stage job-timeline-object ${status}',
@@ -74,7 +77,7 @@ private[ui] class JobPage(parent: JobsTab) extends WebUIPage("job") {
7477 | 'end': new Date( ${completionTime}),
7578 | 'content': '<div class="job-timeline-content" data-toggle="tooltip"' +
7679 | 'data-placement="top" data-html="true"' +
77- | " data-title= \\ " ${Utility .escape(escapedName) } (Stage ${stageId}. ${attemptId})<br>" +
80+ | ' data-title=" ${jsEscapedName } (Stage ${stageId}. ${attemptId})<br>' +
7881 | 'Status: ${status.toUpperCase}<br>' +
7982 | 'Submitted: ${UIUtils .formatDate(new Date (submissionTime))}' +
8083 | ' ${
@@ -84,7 +87,7 @@ private[ui] class JobPage(parent: JobsTab) extends WebUIPage("job") {
8487 " "
8588 }
8689 }">' +
87- | " ${escapedName } (Stage ${stageId}. ${attemptId})</div>" ,
90+ | ' ${jsEscapedName } (Stage ${stageId}. ${attemptId})</div>' ,
8891 |}
8992 """ .stripMargin
9093 }
0 commit comments