Skip to content

Commit a019082

Browse files
committed
SI-9704 don't add a closed HtmlTag if it is already closed
1 parent 7311a29 commit a019082

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/scaladoc/scala/tools/nsc/doc/base/comment/Body.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ final case class HtmlTag(data: String) extends Inline {
8686
}
8787

8888
private val TagsNotToClose = Set("br", "img")
89-
def close = tagName collect { case name if !TagsNotToClose(name) => HtmlTag(s"</$name>") }
89+
def close = tagName collect {
90+
case name if !TagsNotToClose(name) && !data.endsWith(s"</$name>") => HtmlTag(s"</$name>")
91+
}
9092
}
9193

9294
/** The summary of a comment, usually its first sentence. There must be exactly one summary per body. */

test/scaladoc/run/SI-9704.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Chain(List(Chain(List(Text(Demonstrates a scala issue in which the closing link tag is duplicated), Text(
2+
), HtmlTag(<a href="https://link">title</a>), Text(
3+
), Text()))))
4+
Done.

test/scaladoc/run/SI-9704.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import scala.tools.nsc.doc.model._
2+
import scala.tools.partest.ScaladocModelTest
3+
4+
object Test extends ScaladocModelTest {
5+
override def code = """
6+
object Foo {
7+
/**
8+
* Demonstrates a scala issue in which the closing link tag is duplicated
9+
* <a href="https://link">title</a>
10+
*/
11+
def bar = ???
12+
}
13+
"""
14+
15+
def scaladocSettings = ""
16+
17+
def testModel(root: Package) = {
18+
import access._
19+
val thing = root._object("Foo")._method("bar")
20+
println(thing.comment.get.short)
21+
}
22+
}

0 commit comments

Comments
 (0)