Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonElement's content is not escaped #773

Closed
sandwwraith opened this issue Mar 23, 2020 · 0 comments
Closed

JsonElement's content is not escaped #773

sandwwraith opened this issue Mar 23, 2020 · 0 comments
Assignees
Labels

Comments

@sandwwraith
Copy link
Member

Describe the bug

While JsonElement.toString() produces string with escaped double-quote character,
JsonElement.content.toString() produces unescaped and unquoted string

To Reproduce

val secret = """338="}ha2"""
val j = json {
    "secret" to JsonLiteral(secret)
}
println(j["secret"]) // "338=\"}ha2"
println(j["secret"]?.content) // 338="}ha2

Expected behavior

Special characters (") are escaped in JsonLiteral constructor.

Other possible solutions: discourage work with .content.

It is unclear whether .content should be quoted.

Environment

  • Kotlin version: 1.3.70
  • Library version: 0.20.0
  • Kotlin platforms: all
@qwwdfsad qwwdfsad self-assigned this Mar 23, 2020
@qwwdfsad qwwdfsad removed the bug label Apr 8, 2020
qwwdfsad added a commit that referenced this issue Apr 8, 2020
After investigation, it seems like non-escaped content does not cause any troubles when used by kotlinx.serialization. The only harmful behaviour may be when a user serializes JsonElement by hand expecting it to be fully-compliant (-> escaped). Added a note to clarify it

Addresses #773
qwwdfsad added a commit that referenced this issue Apr 13, 2020
After investigation, it seems like non-escaped content does not cause any troubles when used by kotlinx.serialization. The only harmful behaviour may be when a user serializes JsonElement by hand expecting it to be fully-compliant (-> escaped). Added a note to clarify it

Addresses #773
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants