diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-02-10 17:49:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-10 17:49:53 +0100 |
commit | 5c30c62eba6ab79df147d7f4625a0a928674591a (patch) | |
tree | c3131e03acdc0b292e81cb249d06a3fac5847884 /plugins/javadoc/src/main/kotlin | |
parent | f515abc3118143f1cac62616c02970b2926427a2 (diff) | |
download | dokka-5c30c62eba6ab79df147d7f4625a0a928674591a.tar.gz dokka-5c30c62eba6ab79df147d7f4625a0a928674591a.tar.bz2 dokka-5c30c62eba6ab79df147d7f4625a0a928674591a.zip |
Do not leak implementation details in generated Javadoc links (#2813)
Fixes #2803
Diffstat (limited to 'plugins/javadoc/src/main/kotlin')
-rw-r--r-- | plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/utils.kt | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/utils.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/utils.kt index de6193a7..247c55db 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/utils.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/utils.kt @@ -2,14 +2,37 @@ package org.jetbrains.dokka.javadoc.pages import org.jetbrains.dokka.model.* -internal fun JavadocFunctionNode.getAnchor(): String = - "$name(${parameters.joinToString(",") { - when (val bound = if (it.typeBound is Nullable) it.typeBound.inner else it.typeBound) { - is TypeConstructor -> listOf(bound.dri.packageName, bound.dri.classNames).joinToString(".") - is TypeParameter -> bound.name - is PrimitiveJavaType -> bound.name - is UnresolvedBound -> bound.name - is JavaObject -> "Object" - else -> bound.toString() - } - }})"
\ No newline at end of file +/** + * Returns an unencoded, unescaped function anchor. + * + * Should be URL encoded / HTML escaped at call site, + * depending on usage. + */ +// see the discussion in #2813 related to encoding/escaping this value for ids/hrefs +internal fun JavadocFunctionNode.getAnchor(): String { + val parameters = parameters.joinToString(",") { it.typeBound.asString() } + return "$name($parameters)" +} + +private fun Bound.asString(): String = when (this) { + is Nullable -> this.inner.asString() + is DefinitelyNonNullable -> this.inner.asString() + is TypeConstructor -> listOf(this.dri.packageName, this.dri.classNames).joinToString(".") + is TypeParameter -> this.name + is PrimitiveJavaType -> this.name + is UnresolvedBound -> this.name + is TypeAliased -> this.typeAlias.asString() + is JavaObject -> "Object" + + // Void bound is currently used for return type only, + // which is not used in the anchor generation, but + // the handling for it is added regardless, just in case. + // Note: if you accept `Void` as a param, it'll be a TypeConstructor + Void -> "void" + + // Javadoc format currently does not support multiplatform projects, + // so in an ideal world we should not see Dynamic here, but someone + // might disable the checker or the support for it might be added + // by Dokka or another plugin, so the handling is added just in case. + Dynamic -> "dynamic" +} |