From 110dc89e868b159e9a4e0c9046dedcfcfbc48e0d Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Mon, 13 May 2024 11:34:20 -0700 Subject: [PATCH] Improve URI encoding in pkldoc Only encode characters that are strictly necessary in URI paths. This removes encoding for parentheses, for example. --- pkl-doc/src/main/kotlin/org/pkl/doc/Util.kt | 15 +- .../1.2.3/Module Containing Spaces/index.html | 48 +++--- .../1.2.3/baseModule/BaseClass.html | 42 +++--- .../com.package1/1.2.3/baseModule/index.html | 52 +++---- .../classAnnotations/AnnotatedClass.html | 42 +++--- .../1.2.3/classAnnotations/AnnotatedClss.html | 42 +++--- .../AnnotatedClssWithExpandableComment.html | 42 +++--- .../1.2.3/classAnnotations/index.html | 48 +++--- .../1.2.3/classComments/Comments1.html | 42 +++--- .../1.2.3/classComments/Comments2.html | 42 +++--- .../1.2.3/classComments/Comments3.html | 42 +++--- .../1.2.3/classComments/Comments4.html | 42 +++--- .../1.2.3/classComments/Comments5.html | 42 +++--- .../1.2.3/classComments/Comments6.html | 42 +++--- .../1.2.3/classComments/Comments7.html | 42 +++--- .../1.2.3/classComments/Comments8.html | 42 +++--- .../1.2.3/classComments/index.html | 48 +++--- .../1.2.3/classInheritance/MyClass1.html | 48 +++--- .../1.2.3/classInheritance/MyClass2.html | 54 +++---- .../1.2.3/classInheritance/MyClass3.html | 54 +++---- .../1.2.3/classInheritance/MyClass4.html | 60 ++++---- .../1.2.3/classInheritance/index.html | 48 +++--- .../1.2.3/classMethodComments/Comments.html | 70 ++++----- .../1.2.3/classMethodComments/index.html | 48 +++--- .../1.2.3/classMethodModifiers/Modifiers.html | 48 +++--- .../1.2.3/classMethodModifiers/index.html | 48 +++--- .../TypeAnnotations.html | 132 ++++++++--------- .../classMethodTypeAnnotations/index.html | 48 +++--- .../classMethodTypeReferences/MyClass.html | 42 +++--- .../TypeReferences.html | 82 +++++------ .../classMethodTypeReferences/index.html | 48 +++--- .../ClassWithAnnotatedProperty.html | 42 +++--- .../UserDefinedAnnotation.html | 42 +++--- .../1.2.3/classPropertyAnnotations/index.html | 48 +++--- .../1.2.3/classPropertyComments/Comments.html | 42 +++--- .../1.2.3/classPropertyComments/index.html | 48 +++--- .../classPropertyModifiers/Modifiers.html | 42 +++--- .../1.2.3/classPropertyModifiers/index.html | 48 +++--- .../TypeAnnotations.html | 42 +++--- .../classPropertyTypeAnnotations/index.html | 48 +++--- .../classPropertyTypeReferences/MyClass.html | 42 +++--- .../TypeReferences.html | 42 +++--- .../classPropertyTypeReferences/index.html | 48 +++--- .../1.2.3/classTypeConstraints/Address.html | 42 +++--- .../1.2.3/classTypeConstraints/Person1.html | 42 +++--- .../1.2.3/classTypeConstraints/Person2.html | 42 +++--- .../1.2.3/classTypeConstraints/Project.html | 42 +++--- .../1.2.3/classTypeConstraints/index.html | 48 +++--- .../1.2.3/docExampleSubject1/index.html | 48 +++--- .../1.2.3/docExampleSubject2/index.html | 48 +++--- .../com.package1/1.2.3/docLinks/Person.html | 48 +++--- .../com.package1/1.2.3/docLinks/index.html | 54 +++---- .../1.2.3/methodAnnotations/index.html | 60 ++++---- .../1.2.3/moduleComments/index.html | 48 +++--- .../1.2.3/moduleExtend/ExtendClass.html | 42 +++--- .../1.2.3/moduleExtend/index.html | 56 +++---- .../1.2.3/moduleInfoAnnotation/index.html | 48 +++--- .../moduleMethodCommentInheritance/index.html | 78 +++++----- .../1.2.3/moduleMethodComments/index.html | 76 +++++----- .../1.2.3/moduleMethodModifiers/index.html | 54 +++---- .../moduleMethodTypeAnnotations/index.html | 138 +++++++++--------- .../moduleMethodTypeReferences/MyClass.html | 42 +++--- .../moduleMethodTypeReferences/index.html | 88 +++++------ .../UserDefinedAnnotation.html | 42 +++--- .../UserDefinedAnnotation1.html | 42 +++--- .../UserDefinedAnnotation2.html | 42 +++--- .../modulePropertyAnnotations/index.html | 48 +++--- .../index.html | 48 +++--- .../1.2.3/modulePropertyComments/index.html | 48 +++--- .../1.2.3/modulePropertyModifiers/index.html | 48 +++--- .../modulePropertyTypeAnnotations/index.html | 48 +++--- .../modulePropertyTypeReferences/MyClass.html | 42 +++--- .../modulePropertyTypeReferences/index.html | 48 +++--- .../1.2.3/moduleTypes1/index.html | 48 +++--- .../com.package1/1.2.3/moduleTypes2/Foo.html | 42 +++--- .../1.2.3/moduleTypes2/index.html | 48 +++--- .../nested/nested2/nestedModule/MyClass.html | 42 +++--- .../nested/nested2/nestedModule/index.html | 52 +++---- .../com.package1/1.2.3/shared/MyClass.html | 42 +++--- .../com.package1/1.2.3/shared/index.html | 48 +++--- .../1.2.3/ternalPackage/index.html | 48 +++--- .../1.2.3/typeAliasInheritance/Person2.html | 48 +++--- .../1.2.3/typeAliasInheritance/index.html | 54 +++---- .../1.2.3/typealiases/Person.html | 48 +++--- .../com.package1/1.2.3/typealiases/index.html | 54 +++---- .../com.package1/1.2.3/typealiases2/Foo.html | 42 +++--- .../1.2.3/typealiases2/Person.html | 42 +++--- .../1.2.3/typealiases2/index.html | 48 +++--- .../com.package1/1.2.3/unionTypes/index.html | 48 +++--- .../1.2.3/unlistedClass/index.html | 52 +++---- .../1.2.3/unlistedMethod/MyClass.html | 42 +++--- .../1.2.3/unlistedMethod/index.html | 48 +++--- .../1.2.3/unlistedProperty/MyClass.html | 42 +++--- .../1.2.3/unlistedProperty/index.html | 52 +++---- .../4.5.6/Module3/Class Two {}.html | 42 +++--- .../com.package2/4.5.6/Module3/Class3.html | 48 +++--- .../com.package2/4.5.6/Module3/index.html | 54 +++---- .../files/DocGeneratorTest/output/index.html | 8 +- .../localhost:0/birds/0.5.0/Bird/index.html | 48 +++--- .../birds/0.5.0/allFruit/index.html | 48 +++--- .../birds/0.5.0/catalog/index.html | 48 +++--- .../localhost:0/fruit/1.1.0/Fruit/index.html | 48 +++--- 102 files changed, 2502 insertions(+), 2511 deletions(-) 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)