Skip to content

Commit

Permalink
As per json spec, there is no need to escape a single quote (#4)
Browse files Browse the repository at this point in the history
* As per json spec, there is no need to escape a single quote

* Added testcase for single quote behaviour json stringify
  • Loading branch information
charann01 authored Aug 25, 2024
1 parent c11f840 commit e89ce83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ open class Json {
b.append('"')
for (c in str) {
when (c) {
'\\' -> b.append("\\\\"); '/' -> b.append("\\/"); '\'' -> b.append("\\'")
'\\' -> b.append("\\\\"); '/' -> b.append("\\/");
'"' -> b.append("\\\""); '\b' -> b.append("\\b"); '\u000c' -> b.append("\\f")
'\n' -> b.append("\\n"); '\r' -> b.append("\\r"); '\t' -> b.append("\\t")
else -> b.append(c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ class JsonTest {
fun decodeUnicode() {
assertEquals("aeb", Json.parse(""" "a\u0065b" """))
}

@kotlin.test.Test
fun stringify1(){
assertEquals(
"""{"str":"'","int":1,"bool":true}""",
Json.stringify(Json.parse("""{"str":"'","int":1,"bool":true}"""))
)
}
}

0 comments on commit e89ce83

Please sign in to comment.