Skip to content
Permalink
Browse files

Extensions: Fix percentEncode() for two (un)reserved characters

This makes the newly added test pass. Remove the "*" replacement from
fileSystemEncode(), now that this is done in the called percentEncode().

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
  • Loading branch information...
sschuberth committed Aug 27, 2019
1 parent b9e2693 commit 73536bf6fbca47cae0a523eb39ff228978dfec67
Showing with 6 additions and 3 deletions.
  1. +6 −3 utils/src/main/kotlin/Extensions.kt
@@ -246,9 +246,8 @@ fun String.encodeOrUnknown() = fileSystemEncode().takeUnless { it.isEmpty() } ?:
*/
fun String.fileSystemEncode() =
percentEncode()
// Percent-encoding does not necessarily encode some reserved characters that are invalid in some file
// systems, so map these afterwards.
.replace("*", "%2A")
// Percent-encoding does not necessarily encode some characters that are invalid in some file systems, so map
// these afterwards.
.replace(Regex("(^\\.|\\.$)"), "%2E")
.take(255)

@@ -261,6 +260,10 @@ fun String.percentEncode(): String =
// "+" instead of "%20", so apply the proper mapping here afterwards ("+" in the original string is
// encoded as "%2B").
.replace("+", "%20")
// "*" is a reserved character in RFC 3986.
.replace("*", "%2A")
// "~" is an unreserved character in RFC 3986.
.replace("%7E", "~")

/**
* True if the string is a valid semantic version of the given [type], false otherwise.

0 comments on commit 73536bf

Please sign in to comment.
You can’t perform that action at this time.