aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/resolvers/local
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2020-09-16 15:49:24 +0200
committerKamil Doległo <9080183+kamildoleglo@users.noreply.github.com>2020-09-24 10:57:56 +0200
commitfb75185dee2184c380dcf9330e93b73b33539f99 (patch)
treeae381a3e95b33be1c53a54e5db3bd36c4f2de501 /plugins/base/src/main/kotlin/resolvers/local
parente32bca66e1bf25690fcc54c44cbae367959feb6d (diff)
downloaddokka-fb75185dee2184c380dcf9330e93b73b33539f99.tar.gz
dokka-fb75185dee2184c380dcf9330e93b73b33539f99.tar.bz2
dokka-fb75185dee2184c380dcf9330e93b73b33539f99.zip
Escape special characters in file names
Diffstat (limited to 'plugins/base/src/main/kotlin/resolvers/local')
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt15
1 files changed, 12 insertions, 3 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
index 43ffff85..48e44f5f 100644
--- a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
+++ b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
@@ -105,14 +105,23 @@ open class DokkaLocationProvider(
companion object {
internal val reservedFilenames = setOf("index", "con", "aux", "lst", "prn", "nul", "eof", "inp", "out")
+ //Taken from: https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names
+ internal val reservedCharacters = setOf('|', '>', '<', '*', ':', '"', '?', '%')
internal fun identifierToFilename(name: String): String {
if (name.isEmpty()) return "--root--"
- val escaped = name.replace("[<>]".toRegex(), "-")
- val lowercase = escaped.replace("[A-Z]".toRegex()) { matchResult -> "-" + matchResult.value.toLowerCase() }
- return if (lowercase in reservedFilenames) "--$lowercase--" else lowercase
+ return sanitizeFileName(name, reservedFilenames, reservedCharacters)
}
}
}
+internal fun sanitizeFileName(name: String, reservedFileNames: Set<String>, reservedCharacters: Set<Char>): String {
+ val lowercase = name.replace("[A-Z]".toRegex()) { matchResult -> "-" + matchResult.value.toLowerCase() }
+ val withoutReservedFileNames = if (lowercase in reservedFileNames) "--$lowercase--" else lowercase
+ return reservedCharacters.fold(withoutReservedFileNames){
+ acc, character ->
+ if(character in acc) acc.replace(character.toString(), "[${character.toInt()}]")
+ else acc
+ }
+}