Skip to content

Commit 0761e5f

Browse files
committed
address andrew's comments
1 parent ebe1182 commit 0761e5f

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

core/src/main/scala/org/apache/spark/ui/UIUtils.scala

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,14 @@ private[spark] object UIUtils extends Logging {
416416
* Note: In terms of security, only anchor tags with root relative links are supported. So any
417417
* attempts to embed links outside Spark UI, or other tags like <script> will cause in the whole
418418
* description to be treated as plain text.
419+
*
420+
* @param desc the original job or stage description string, which may contain html tags.
421+
* @param basePathUri with which to prepend the relative links; this is used when plainText is
422+
* false.
423+
* @param plainText whether to keep only plain text (i.e. remove html tags) from the original
424+
* description string.
425+
* @return the HTML rendering of the job or stage description, which will be a Text when plainText
426+
* is true, and an Elem otherwise.
419427
*/
420428
def makeDescription(desc: String, basePathUri: String, plainText: Boolean = false): NodeSeq = {
421429
import scala.language.postfixOps
@@ -445,32 +453,33 @@ private[spark] object UIUtils extends Logging {
445453
"Links in job descriptions must be root-relative:\n" + allLinks.mkString("\n\t"))
446454
}
447455

448-
val rule = if (plainText) {
449-
// Remove all tags, retaining only their texts
450-
new RewriteRule() {
451-
override def transform(n: Node): Seq[Node] = {
452-
n match {
453-
case e: Elem if e.child isEmpty => Text(e.text)
454-
case e: Elem if e.child nonEmpty => Text(e.child.flatMap(transform).text)
455-
case _ => n
456+
val rule =
457+
if (plainText) {
458+
// Remove all tags, retaining only their texts
459+
new RewriteRule() {
460+
override def transform(n: Node): Seq[Node] = {
461+
n match {
462+
case e: Elem if e.child isEmpty => Text(e.text)
463+
case e: Elem if e.child nonEmpty => Text(e.child.flatMap(transform).text)
464+
case _ => n
465+
}
456466
}
457467
}
458468
}
459-
}
460-
else {
461-
// Prepend the relative links with basePathUri
462-
new RewriteRule() {
463-
override def transform(n: Node): Seq[Node] = {
464-
n match {
465-
case e: Elem if e \ "@href" nonEmpty =>
466-
val relativePath = e.attribute("href").get.toString
467-
val fullUri = s"${basePathUri.stripSuffix("/")}/${relativePath.stripPrefix("/")}"
468-
e % Attribute(null, "href", fullUri, Null)
469-
case _ => n
469+
else {
470+
// Prepend the relative links with basePathUri
471+
new RewriteRule() {
472+
override def transform(n: Node): Seq[Node] = {
473+
n match {
474+
case e: Elem if e \ "@href" nonEmpty =>
475+
val relativePath = e.attribute("href").get.toString
476+
val fullUri = s"${basePathUri.stripSuffix("/")}/${relativePath.stripPrefix("/")}"
477+
e % Attribute(null, "href", fullUri, Null)
478+
case _ => n
479+
}
470480
}
471481
}
472482
}
473-
}
474483
new RuleTransformer(rule).transform(xml)
475484
} catch {
476485
case NonFatal(e) =>

core/src/main/scala/org/apache/spark/ui/jobs/AllJobsPage.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ private[ui] class AllJobsPage(parent: JobsTab) extends WebUIPage("") {
7171
val jobId = jobUIData.jobId
7272
val status = jobUIData.status
7373
val (jobName, jobDescription) = getLastStageNameAndDescription(jobUIData)
74-
val displayJobDescription = if (jobDescription.isEmpty) {
75-
jobName
76-
} else {
77-
UIUtils.makeDescription(jobDescription, "", plainText = true).text
78-
}
74+
val displayJobDescription =
75+
if (jobDescription.isEmpty) {
76+
jobName
77+
} else {
78+
UIUtils.makeDescription(jobDescription, "", plainText = true).text
79+
}
7980
val submissionTime = jobUIData.submissionTime.get
8081
val completionTimeOpt = jobUIData.completionTime
8182
val completionTime = completionTimeOpt.getOrElse(System.currentTimeMillis())

0 commit comments

Comments
 (0)