Skip to content

hande single quotes when isLenient=true #2765

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

Closed
lisonge opened this issue Aug 8, 2024 · 3 comments
Closed

hande single quotes when isLenient=true #2765

lisonge opened this issue Aug 8, 2024 · 3 comments

Comments

@lisonge
Copy link

lisonge commented Aug 8, 2024

Describe the bug

To Reproduce

package li.songe.gkd

import kotlinx.serialization.json.Json
import org.junit.Test

class ExampleUnitTest {
    @Test
    fun check() {
        val json = Json {
            isLenient = true
        }

        val okStr = """
            {
              a: ['a']
            }
        """.trimIndent()
        println(json.parseToJsonElement(okStr))

        val errStr = """
            {
              a: ['[']
            }
        """.trimIndent()
        println(json.parseToJsonElement(errStr))
    }
}

Expected behavior
parse success

Actual behavior

{"a":['a']}

Unexpected JSON token at offset 10: Expected end of the array or comma at path: $
JSON input: {
  a: ['[']
}
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 10: Expected end of the array or comma at path: $
JSON input: {
  a: ['[']
}

image

Environment

  • Kotlin version: [2.0.10]
  • Library version: [1.7.1]
  • Kotlin platforms: [JVM]
  • Gradle version: [8.9]
@lisonge
Copy link
Author

lisonge commented Aug 8, 2024

my config file string is json5 format

i find #797 is closed, but it doesn't support json5

@lisonge
Copy link
Author

lisonge commented Aug 11, 2024

The following string also causes parsing errors

{
    a: ['"a']
}

and

{
    a: 'a'
}

will got 'a'(length=3) instead of a(length=1)

This isLenient=true mode is not quite what I expected

In JSON5 parsing, single quotes should create an independent string context rather than being meaningless tokens

@lisonge lisonge changed the title [BUG] isLenient is not work when string includes [ [BUG] error hande single quotes when isLenient=true Aug 11, 2024
@lisonge lisonge mentioned this issue Aug 11, 2024
@lisonge lisonge changed the title [BUG] error hande single quotes when isLenient=true hande single quotes when isLenient=true Aug 11, 2024
@lisonge
Copy link
Author

lisonge commented Aug 14, 2024

@lisonge lisonge closed this as completed Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant