Skip to content

Commit

Permalink
Fix untrimmed secrets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernasss12 committed Jul 30, 2023
1 parent dce1a90 commit 37b3680
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/kotlin/dev/bernasss12/util/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object Common {
private val multiUnderscoresRegex = "_+".toRegex()

/**
* Looks for a file named "badge-server-ua" or defaults
* Tries to get the user agent from the badge-server-ua file.
*/
fun getUserAgent(logger: Logger): String {
return getPrivateString("badge-server-ua", logger)
Expand All @@ -29,15 +29,15 @@ object Common {
// Try current directory
Paths.get("", filename).toAbsolutePath().let { currentPath ->
if (currentPath.exists()) {
return currentPath.readText()
return currentPath.readText().trim()
}
}

// Try config folder
val homePath = System.getProperty("user.home")
Paths.get(homePath, ".config", filename).toAbsolutePath().let { configPath ->
if (configPath.exists()) {
return configPath.readText()
return configPath.readText().trim()
}
}

Expand All @@ -46,7 +46,7 @@ object Common {
if (envPath.isNotBlank()) {
Paths.get(envPath, filename).let { environmentPath ->
if (environmentPath.exists()) {
return environmentPath.readText()
return environmentPath.readText().trim()
}
}
}
Expand All @@ -58,6 +58,7 @@ object Common {
fun getTempFolder(): File = File("temp").also { it.mkdir() }
fun makeSafeIdentifier(text: String): String =
text.replace(unsafeRegex, "_").replace(multiUnderscoresRegex, "_")

fun tempFile(prefix: String, text: String, extension: String = ""): Path =
getTempFolder().toPath().resolve("${prefix}-${makeSafeIdentifier(text)}" + if (extension.isBlank()) "" else ".$extension")

Expand All @@ -68,7 +69,7 @@ object Common {
}
inkscapeProcess.waitFor()
inkscapeProcess.inputReader().readText().takeIf { it.isNotBlank() }.also {
logger.debug("Inkscape standard output: $it" )
logger.debug("Inkscape standard output: $it")
}
inkscapeProcess.errorReader().readText().takeIf { it.isNotBlank() }.also {
logger.debug("Inkscape error output: $it")
Expand Down

0 comments on commit 37b3680

Please sign in to comment.