@@ -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) =>
0 commit comments