Skip to content

Commit

Permalink
Backport "Fix #19524: Protect use of HeaderIdGenerator with `synchr…
Browse files Browse the repository at this point in the history
…onized`." to LTS (#20978)

Backports #19884 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 3, 2024
2 parents 26fb24a + b48eee3 commit 1c11610
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ object SectionRenderingExtension extends HtmlRenderer.HtmlRendererExtension:
val idSuffix = repeatedIds.getOrElseUpdate((c, headerText), 0)
val ifSuffixStr = if(idSuffix == 0) then "" else idSuffix.toString
repeatedIds.update((c, headerText), idSuffix + 1)
val id = idGenerator.getId(headerText + ifSuffixStr)

/* #19524 flexmark's `HeaderIdGenerator` does not appear to be thread-safe,
* so we protect its usage with a full `synchronize`.
*/
val id = idGenerator.synchronized {
idGenerator.getId(headerText + ifSuffixStr)
}

val anchor = AnchorLink(s"#$id")
val headerClass: String = header.getLevel match
case 1 => "h500"
Expand Down

0 comments on commit 1c11610

Please sign in to comment.