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

Error on unquoted string gives incorrect position #2360

Closed
sandwwraith opened this issue Jul 10, 2023 · 0 comments
Closed

Error on unquoted string gives incorrect position #2360

sandwwraith opened this issue Jul 10, 2023 · 0 comments
Assignees

Comments

@sandwwraith
Copy link
Member

sandwwraith commented Jul 10, 2023

Describe the bug

If key or value in Json is not quoted (e.g. one wanted to parse a data in lenient mode, but forgot to turn it on),
the position points to the end of such value, but message mentions the beginning:

To Reproduce

@Test
fun lenientIncorrect() {
        val input1 = """{boxed:str}"""
        val input2 = """{"boxed":str}"""
        val ser = serializer<Box<String>>()
        Json.decodeFromString(ser, input2)
}

Expected behavior

Parsing input2 gives

kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 11: Expected quotation mark '"', but had 'r' instead at path: $.boxed
JSON input: {"boxed":str}

although message should be 'had s instead' and position 8, to point at the beginning of the string where quotation is expected.

Parsing input1 gives

JSON input: {boxed:str}

Same here: should have offset=1 and message 'had b instead'.

Reason: consumeStringLenient here advances position and doesn't roll it back.

Environment

  • Kotlin version: 1.8.21
  • Library version: 1.5.1
  • Kotlin platforms: JVM
@sandwwraith sandwwraith self-assigned this Jul 10, 2023
sandwwraith added a commit that referenced this issue Aug 8, 2023
To avoid cryptic and incorrect ones, such as `Expected quotation mark '"', but had '"' instead`.

Fixes #2360
Fixes #2399
sandwwraith added a commit that referenced this issue Aug 9, 2023
To avoid cryptic and incorrect ones, such as `Expected quotation mark '"', but had '"' instead` or `unexpected token: 10`.

Fixes #2360
Fixes #2399

Also remove @PublishedApi from BATCH_SIZE to remove it from public API dump.
sandwwraith added a commit that referenced this issue Aug 11, 2023
To avoid cryptic and incorrect ones, such as `Expected quotation mark '"', but had '"' instead` or `unexpected token: 10`.

Fixes #2360
Fixes #2399

Also remove @PublishedApi from BATCH_SIZE to remove it from public API dump.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant