diff --git a/pkl-doc/src/main/kotlin/org/pkl/doc/Util.kt b/pkl-doc/src/main/kotlin/org/pkl/doc/Util.kt index 2064f4bc..cb1b1556 100644 --- a/pkl-doc/src/main/kotlin/org/pkl/doc/Util.kt +++ b/pkl-doc/src/main/kotlin/org/pkl/doc/Util.kt @@ -119,18 +119,11 @@ internal fun String.replaceSourceCodePlaceholders( .replace("%{endLine}", sourceLocation.endLine.toString()) } -/** - * Encodes a URI string, encoding characters that are part of URI syntax. - * - * Follows `encodeURIComponent` from ECMAScript. - */ +/** Encodes a URI string, encoding characters that are part of URI syntax. */ internal val String.uriEncodedComponent get(): String { - val ret = URLEncoder.encode(this, StandardCharsets.UTF_8) - // Replace `+` with `%20` to be safe - // (see - // https://stackoverflow.com/questions/2678551/when-should-space-be-encoded-to-plus-or-20#:~:text=%20%20is%20a%20valid%20way,encodeURIComponent()%20does%20in%20JavaScript.) - return ret.replace("+", "%20") + val ret = URI(null, null, this, null) + return ret.toString().replace("/", "%2F") } /** @@ -144,8 +137,6 @@ internal val String.uriEncoded fun getModulePath(moduleName: String, packagePrefix: String): String = moduleName.substring(packagePrefix.length).replace('.', '/') -internal fun String.toEncodedUri(): URI = URI(uriEncoded) - /** * Turns `"foo.bar.baz-biz"` into ``"foo.bar.`baz-biz`"``. * diff --git a/pkl-doc/src/test/files/DocGeneratorTest/output/com.package1/1.2.3/Module Containing Spaces/index.html b/pkl-doc/src/test/files/DocGeneratorTest/output/com.package1/1.2.3/Module Containing Spaces/index.html index 5ca600da..b6175f1e 100644 --- a/pkl-doc/src/test/files/DocGeneratorTest/output/com.package1/1.2.3/Module Containing Spaces/index.html +++ b/pkl-doc/src/test/files/DocGeneratorTest/output/com.package1/1.2.3/Module Containing Spaces/index.html @@ -64,8 +64,8 @@

Methods(show inherited)