Skip to content

Commit

Permalink
Fix escape with unicode letters, close #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Sep 10, 2020
1 parent acb6ba0 commit 354c8f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ internal fun String.getQuotationAvailability(): Int {
doubleWithoutEscape = false
canBeUnquoted = false
}
doubleWithoutEscape && REPLACEMENT_CHARS[c.toInt()] != null -> {
doubleWithoutEscape && REPLACEMENT_CHARS.getOrNull(c.toInt()) != null -> {
doubleWithoutEscape = false
}
c == '\'' -> canBeSingleQuoted = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import kotlin.test.assertFailsWith

internal class DecoderEscapeTest {

@Test
fun escapeColon() {
assertEquals(
":",
default.decodeAnyFromString(
"""":""""
)
)
}

@Test
fun escapeMapping() {
val mappings: Map<String, String> = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ internal class TestEncoderEscape {
assertEquals("\'\n\'", best.encodeToString<String>("\n")) // will adjust to single
}

@Test
fun colonEscape() {
assertEquals("\":\"", double.encodeToString<String>(":"))
assertEquals("\':\'", single.encodeToString<String>(":"))
assertEquals("\':\'", none.encodeToString<String>(":"))
assertEquals("\':\'", best.encodeToString<String>(":"))
}

@Test
fun colonEscapeWithChinese() {
assertEquals("\":好\"", double.encodeToString<String>(":好"))
assertEquals("\':好\'", single.encodeToString<String>(":好"))
assertEquals("\':好\'", none.encodeToString<String>(":好"))
assertEquals("\':好\'", best.encodeToString<String>(":好"))
}

@Test
fun spaceEscape() {
assertEquals("\" \"", double.encodeToString<String>(" "))
assertEquals("\' \'", single.encodeToString<String>(" "))
assertEquals("\' \'", none.encodeToString<String>(" "))
assertEquals("\' \'", best.encodeToString<String>(" "))
}

@Test
fun testUnicodeEscape() {
assertEquals(
Expand Down

0 comments on commit 354c8f1

Please sign in to comment.