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

KeyEmpty value causes yamlKT parser to nest susequent key/value pairs into Empty field #73

Open
philip0402 opened this issue Jun 28, 2024 · 0 comments

Comments

@philip0402
Copy link

philip0402 commented Jun 28, 2024

Example of Bug:

  val validYaml = "id: lgcbkyz4c6b5gnfsupczfkn\n" + 
                             "title: Truth\n" + 
                             "desc: \n" + 
                             "updated: 1704581169935\n" + 
                             "created: 1704049864411\n"
   val map: YamlMap = Yaml.decodeYamlMapFromString(validYaml)
   println("Parsed YAML map: $map")

Expected output:

ParsedYAMLmap:{id:lgcbkyz4c6b5gnfsupczfkn,title:Truth,desc: ,updated:1704581169935,created:1704049864411}

Actual output:

ParsedYAMLmap:{id:lgcbkyz4c6b5gnfsupczfkn,title:Truth,desc:{updated:1704581169935,created:1704049864411}}

Test which reproduces bug:

@Test
    fun testBlankDescription() {
        val validYaml = "id: lgcbkyz4c6b5gnfsupczfkn\n" + "title: Truth\n" + "desc: \n" + "updated: 1704581169935\n" + "created: 1704049864411\n"
        val map: YamlMap = Yaml.decodeYamlMapFromString(validYaml)
        println("Parsed YAML map: $map")
        assertTrue { map.containsKey(YamlPrimitive("desc")) }
        assertTrue { map.containsKey(YamlPrimitive("updated")) }
        assertTrue { map.containsKey(YamlPrimitive("created")) }
    }

Test Results:

Pass:

  • assertTrue { map.containsKey(YamlPrimitive("desc")) }

Assertion Errors:

  • assertTrue { map.containsKey(YamlPrimitive("updated")) }
  • assertTrue { map.containsKey(YamlPrimitive("created")) }

Debugging Logic:

Function decodeYamlMapFromString is called. Stepping into the function implementation.

Screenshot 2024-06-28 at 2 37 03 PM

Function decodeYamlMapFromString calls decodeFromString. Stepping into the function implementation.

Note: The function was edited for debugging purposes. val yamlMap was created to keep track of the return value of the deserialize function call.

 deserializer.deserialize(YamlDecoder(configuration, TokenStream(string), serializersModule))

Screenshot 2024-06-28 at 2 38 29 PM

Function deserialize is called. Stepping into the function implementation. The program steps into the conditional code block and calls the deserialize function from the kotlinx library.

Screenshot 2024-06-28 at 3 02 25 PM

Screenshot 2024-06-28 at 3 03 43 PM

Results:

The issue seems to come from the parsing done by the deserialize function call made from the kotlinx library.

Moving forward:

The yamlkt parser should explicitly address the issue of empty values in the key/value mappings.

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