Github user zsxwing commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8791#discussion_r40110059
  
    --- Diff: core/src/main/scala/org/apache/spark/ui/UIUtils.scala ---
    @@ -395,4 +397,55 @@ private[spark] object UIUtils extends Logging {
         </script>
       }
     
    +  /**
    +   * Convert a description string to HTML. It will try to parse the string 
as HTML and sanitize
    +   * any links. If that fails, then whole string will treated as a simple 
text.
    +   */
    +  def makeDescription(desc: String, basePathUri: String): NodeSeq = {
    +    import scala.language.postfixOps
    +
    +    // If the description can be parsed as HTML and has only relative 
links, then render
    +    // as HTML, otherwise render as escaped string
    +    try {
    +      // Try to load the description as unescaped HTML
    +      val xml = XML.loadString(s"""<span 
class="description-input">$desc</span>""")
    +
    +      // Verify that this has only anchors and span (we are wrapping in 
span)
    +      val allowedNodeLabels = Set("a", "span")
    +      val illegalNodes = xml \\ "_"  filterNot { case node: Node =>
    +        allowedNodeLabels.contains(node.label)
    +      }
    +      if (illegalNodes.nonEmpty) {
    +        throw new IllegalArgumentException(
    +          "Only HTML anchors allowed in job descriptions\n" +
    +            illegalNodes.map { n => s"${n.label} in $n"}.mkString("\n\t"))
    +      }
    +
    +      // Verify that all links are relative links starting with "/"
    +      val allLinks =
    +        xml \\ "a" flatMap { _.attributes } filter { _.key == "href" } map 
{ _.value.toString }
    +      if (allLinks.exists { ! _.startsWith ("/") }) {
    +        throw new IllegalArgumentException(
    +          "Links in job descriptions must be relative:\n" + 
allLinks.mkString("\n\t"))
    --- End diff --
    
    I think both `/link` and `link` are called relative links. But `/link` is 
called `root-relative link`. Maybe we should use `Links in job descriptions 
must be root-relative:\n` here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to