diff --git a/java-dotenv-3.3.1.pom b/java-dotenv-3.3.1.pom deleted file mode 100644 index 5f1d1ff..0000000 --- a/java-dotenv-3.3.1.pom +++ /dev/null @@ -1,206 +0,0 @@ - - - 4.0.0 - - java-dotenv - Environment based config for the JVM - https://github.com/cdimascio/java-dotenv - - io.github.cdimascio - java-dotenv - 3.3.1 - - - - Apache License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - repo - A business-friendly OSS license - - - - - Carmine DiMascio OSS - https://github.com/cdimascio - - - - scm:github:https://github.com/cdimascio/java-dotenv - scm:github:https://github.com/cdimascio/java-dotenv - master - https://github.com/cdimascio/java-dotenv - - - - - cdimascio - Carmine DiMascio - cdimascio@gmail.com - https://www.github.com/cdimascio - Carmine DiMascio OSS - https://www.github.com/cdimascio - - developer - - America/New_York - - - - - - 1.3.21 - io.cdimascio.DotenvKt - 4.12 - UTF-8 - - 3.0.1 - 3.0.0 - 0.9.15 - cdimascio - maven - java-dotenv - - - - - - jcenter - JCenter - https://jcenter.bintray.com/ - - - - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - compile - - - - junit - junit - ${junit.version} - test - - - - org.jetbrains.kotlin - kotlin-test-junit - ${kotlin.version} - test - - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - - compile - - compile - - - - - test-compile - - test-compile - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - - true - ${main.class} - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20.1 - - ${project.basedir} - - - - org.apache.maven.plugins - maven-source-plugin - ${maven.source.plugin} - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven.javadoc.plugin} - - - attach-javadocs - - jar - - - - - - org.jetbrains.dokka - dokka-maven-plugin - ${dokka.version} - - - pre-site - - dokka - - - - - - org.jacoco - jacoco-maven-plugin - 0.7.6.201602180812 - - - prepare-agent - - prepare-agent - - - - - - org.eluder.coveralls - coveralls-maven-plugin - 4.3.0 - - i3Bl4av26PMqZNekY8X3Jt7t6YhwFXKFu - - - - - diff --git a/pom.xml b/pom.xml index 44ccbb4..a9543c4 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.github.cdimascio java-dotenv - 3.3.1 + 4.0.0 diff --git a/src/main/kotlin/io/github/cdimascio/dotenv/internal/DotenvParser.kt b/src/main/kotlin/io/github/cdimascio/dotenv/internal/DotenvParser.kt index 9274825..d99877e 100644 --- a/src/main/kotlin/io/github/cdimascio/dotenv/internal/DotenvParser.kt +++ b/src/main/kotlin/io/github/cdimascio/dotenv/internal/DotenvParser.kt @@ -16,7 +16,7 @@ internal class DotenvParser( private val isWhiteSpace = { s: String -> """^\s*${'$'}""".toRegex().matches(s) } private val isComment = { s: String -> s.startsWith("#") || s.startsWith("""//""") } private val parseLine = { s: String -> """^\s*([\w.\-]+)\s*(=)\s*(.*)?\s*$""".toRegex().matchEntire(s) } - + private val isQuoted = { s: String -> s.startsWith("\"") && s.endsWith("\"") } /** * Parses the contents of .env and returns the environment variable and associated value as a list of pairs * @return a list of pair representing the values .env is contributing to the virtual environment @@ -37,11 +37,16 @@ internal class DotenvParser( val match = parseLine(it) if (match != null) { val (key, _, value) = match.destructured - Pair(key, value) + Pair(key, normalizeValue(value)) } else { if (throwIfMalformed) throw DotEnvException("Malformed entry: $it") else null } } } + + private fun normalizeValue(value: String): String { + val tr = value.trim() + return if (isQuoted(tr)) tr.substring(1 until value.length -1) else tr + } } diff --git a/src/test/kotlin/tests/DslTests.kt b/src/test/kotlin/tests/DslTests.kt index 667a57b..836a770 100644 --- a/src/test/kotlin/tests/DslTests.kt +++ b/src/test/kotlin/tests/DslTests.kt @@ -12,7 +12,8 @@ class DotEnvDslTest { private val envVars = mapOf( "MY_TEST_EV1" to "my test ev 1", "MY_TEST_EV2" to "my test ev 2", - "WITHOUT_VALUE" to "" + "WITHOUT_VALUE" to "", + "QUOTED_EV1" to "jdbc:hive2://[domain]:10000/default;principal=hive/_HOST@[REALM]" ) @test(expected = DotEnvException::class) @@ -20,6 +21,21 @@ class DotEnvDslTest { dotenv() } + @test + fun dotenvQuotedEv() { + val env = dotenv { + ignoreIfMalformed = true + } + + envVars.forEach { + val expected = it.value + val actual = env[it.key] + assertEquals(expected, actual) + } + + assertEquals("jdbc:hive2://[domain]:10000/default;principal=hive/_HOST@[REALM]", env["QUOTED_EV1"]) + } + @test fun dotenvIgnoreMalformed() { val env = dotenv { diff --git a/src/test/resources/.env b/src/test/resources/.env index 8f89b1e..6a79064 100644 --- a/src/test/resources/.env +++ b/src/test/resources/.env @@ -5,3 +5,5 @@ WITHOUT_VALUE= ## Malformed EV! MY_TEST_EV3 + +QUOTED_EV1="jdbc:hive2://[domain]:10000/default;principal=hive/_HOST@[REALM]"