Skip to content

Fix: Validation for API link #17099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ trait SiteRenderer(using DocContext) extends Locations:
def siteContent(pageDri: DRI, content: ResolvedTemplate): PageContent =
import content.ctx
def tryAsDri(str: String): Option[String] =
val (path, prefix) = str match
val newStr =
str.dropWhile(c => c == '.' || c == '/').replaceAll("/", ".") match
case str if str.endsWith("$.html") => str.stripSuffix("$.html")
case str if str.endsWith(".html") => str.stripSuffix(".html")
case _ => str

val (path, prefix) = newStr match
case HashRegex(path, prefix) => (path, prefix)
case _ => (str, "")
case _ => (newStr, "")

val res = ctx.driForLink(content.template.file, path).filter(driExists)
res.headOption.map(pathToPage(pageDri, _) + prefix)
Expand All @@ -49,7 +55,7 @@ trait SiteRenderer(using DocContext) extends Locations:

/* Link resolving checks performs multiple strategies with following priority:
1. We check if the link is a valid URL e.g. http://dotty.epfl.ch
2. We check if the link leads to other static site
2. We check if the link leads to other static site or API pages, example: [[exemple.scala.Foo]] || [Foo](../exemple/scala/Foo.html)
3. We check if the link leads to existing asset e.g. images/logo.svg -> <static-site-root>/_assets/images/logo.svg
*/

Expand Down