mirror of
https://github.com/apple/pkl.git
synced 2026-07-02 19:21:41 +02:00
Fix parsing of external property values containing = (#631)
This commit is contained in:
committed by
GitHub
parent
e5b7e046d9
commit
a8f24c9f13
@@ -68,8 +68,8 @@ class BaseOptions : OptionGroup() {
|
|||||||
fun RawOption.associateProps():
|
fun RawOption.associateProps():
|
||||||
OptionWithValues<Map<String, String>, Pair<String, String>, Pair<String, String>> {
|
OptionWithValues<Map<String, String>, Pair<String, String>, Pair<String, String>> {
|
||||||
return convert {
|
return convert {
|
||||||
val parts = it.split("=")
|
val eq = it.indexOf('=')
|
||||||
if (parts.size <= 1) parts[0] to "true" else parts[0] to parts[1]
|
if (eq == -1) it to "true" else it.substring(0, eq) to it.substring(eq + 1)
|
||||||
}
|
}
|
||||||
.multiple()
|
.multiple()
|
||||||
.toMap()
|
.toMap()
|
||||||
|
|||||||
@@ -44,11 +44,12 @@ class BaseCommandTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `external properties without value default to 'true'`() {
|
fun `difficult cases for external properties`() {
|
||||||
cmd.parse(arrayOf("-p", "flag1", "-p", "flag2=", "-p", "FOO=bar"))
|
cmd.parse(arrayOf("-p", "flag1", "-p", "flag2=", "-p", "FOO=bar", "-p", "baz=qux=quux"))
|
||||||
val props = cmd.baseOptions.baseOptions(emptyList()).externalProperties
|
val props = cmd.baseOptions.baseOptions(emptyList()).externalProperties
|
||||||
|
|
||||||
assertThat(props).isEqualTo(mapOf("flag1" to "true", "flag2" to "", "FOO" to "bar"))
|
assertThat(props)
|
||||||
|
.isEqualTo(mapOf("flag1" to "true", "flag2" to "", "FOO" to "bar", "baz" to "qux=quux"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user