summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2010-04-12 14:16:01 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2010-04-12 14:16:01 +0000
commite96091a44f1192d3c11dce391e648a1f24121766 (patch)
treec5b3a3e439ccb930c058cfd2ed7ba531f4bf6288 /src
parent484134e4f5fbc433ea1706ab8caf10cfa6bd58c7 (diff)
downloadscala-e96091a44f1192d3c11dce391e648a1f24121766.tar.gz
scala-e96091a44f1192d3c11dce391e648a1f24121766.tar.bz2
scala-e96091a44f1192d3c11dce391e648a1f24121766.zip
[scaladoc] Dangerous HTML (that can break Scala...
[scaladoc] Dangerous HTML (that can break Scaladoc) is stripped out of comments and replaced by corresponding wiki syntax when possible. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala b/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala
index 0aff68ab02..198fbcc6f3 100644
--- a/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala
@@ -45,8 +45,8 @@ trait CommentFactory { thisFactory: ModelFactory with CommentFactory =>
}
}
- protected val endOfText = '\u0003'
- protected val endOfLine = '\u000A'
+ protected val endOfText = '\u0003'
+ protected val endOfLine = '\u000A'
/** Something that should not have happened, happened, and Scaladoc should exit. */
protected def oops(msg: String): Nothing =
@@ -56,6 +56,21 @@ trait CommentFactory { thisFactory: ModelFactory with CommentFactory =>
protected val CleanCommentLine =
new Regex("""(?:\s*\*\s?)?(.*)""")
+ /** Dangerous HTML tags that should be replaced by something safer, such as wiki syntax, or that should be dropped. */
+ protected val DangerousHtml =
+ new Regex("""<(/?(?:p|div|pre|ol|ul|li|h[1-6]))[^>]*>""")
+
+ /** Maps a dangerous HTML tag to a safe wiki replacement, or an empty string if it cannot be salvaged. */
+ protected def htmlReplacement(mtch: Regex.Match): String = mtch.matched match {
+ case "p" | "div" => "\n\n"
+ case "h1" | "h2" | "h3" | "h4" | "h5" | "h6" => "\n= "
+ case "/h1" | "/h2" | "/h3" | "/h4" | "/h5" | "/h6" => " =\n"
+ case "pre" => "{{{"
+ case "/pre" => "}}}"
+ case "li" => "\n - "
+ case _ => ""
+ }
+
/** A Scaladoc tag not linked to a symbol. Returns the name of the tag, and the rest of the line. */
protected val SimpleTag =
new Regex("""\s*@(\S+)\s+(.*)""")
@@ -99,7 +114,9 @@ trait CommentFactory { thisFactory: ModelFactory with CommentFactory =>
tl
}
}
- comment.trim.stripPrefix("/*").stripSuffix("*/").lines.toList map (cleanLine(_))
+ val strippedComment = comment.trim.stripPrefix("/*").stripSuffix("*/")
+ val safeComment = DangerousHtml.replaceAllIn(strippedComment, { htmlReplacement(_) })
+ safeComment.lines.toList map (cleanLine(_))
}
/** Parses a comment (in the form of a list of lines) to a Comment instance, recursively on lines. To do so, it