Skip to content

Commit

Permalink
Fixes empty lines in yaml maps (#1570)
Browse files Browse the repository at this point in the history
Fix from @jobe-m backported from korlibs/kproject#12
  • Loading branch information
soywiz authored May 4, 2023
1 parent 5b97cea commit e479b66
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ object Yaml {
// Line start
flush()
val indentStr = readWhile(Char::isWhitespace).replace("\t", " ")
if (indentStr.contains('\n')) continue@linestart // ignore empty lines with possible additional indent
val indent = indentStr.length
if (indents.isEmpty() || indent > indents.last()) {
indents += indent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,38 @@ class YamlTest {
// )
//}

@Test
fun testMapListIssue() {
assertEquals(
mapOf(
"hello" to listOf("a", "b"),
"world" to listOf("c", "d"),
"test" to listOf("e", "f")
),
Yaml.decode("""
hello:
- a
- b
world:
- c
- d
test:
- e
- f
""".trimIndent())
)
}
@Test
fun testMapListIssue() {
val testYmlString = """
hello:
- a
- b
lineWithSpaces:
- aa
- bb
world:
- c
- d
test:
- e
- f
""".trimIndent()
//println("\n\n[[[$testYmlString]]]\n\n")
assertEquals(
mapOf(
"hello" to listOf("a", "b"),
"lineWithSpaces" to listOf("aa", "bb"),
"world" to listOf("c", "d"),
"test" to listOf("e", "f")
),
Yaml.decode(testYmlString)
)
}

@Test
fun testWindowsLineEndings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ internal object Yaml {
// Line start
flush()
val indentStr = readWhile(Char::isWhitespace).replace("\t", " ")
if (indentStr.contains('\n')) continue@linestart // ignore empty lines with possible additional indent
val indent = indentStr.length
if (indents.isEmpty() || indent > indents.last()) {
indents += indent
Expand Down
33 changes: 22 additions & 11 deletions korte/src/commonTest/kotlin/korlibs/template/YamlTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,34 @@ class YamlTest {

@Test
fun testMapListIssue() {
val testYmlString = """
hello:
- a
- b
lineWithSpaces:
- aa
- bb
world:
- c
- d
test:
- e
- f
""".trimIndent()
//println("\n\n[[[$testYmlString]]]\n\n")
assertEquals(
mapOf(
"hello" to listOf("a", "b"),
"lineWithSpaces" to listOf("aa", "bb"),
"world" to listOf("c", "d"),
"test" to listOf("e", "f")
),
Yaml.decode("""
hello:
- a
- b
world:
- c
- d
test:
- e
- f
""".trimIndent())
Yaml.decode(testYmlString)
)
}

Expand Down

0 comments on commit e479b66

Please sign in to comment.