Skip to content
This repository was archived by the owner on Nov 30, 2025. It is now read-only.
This repository was archived by the owner on Nov 30, 2025. It is now read-only.

YamlNodeSerializer corrupts data due to implicit types conversion #749

@eugene-krivobokov

Description

@eugene-krivobokov

Describe the bug

Hi! YamlNode loses data and types due to implicit automatic conversion to numbers.

"+44123456" -> 44123456

Reproduction repo

N/A

Steps to reproduce

@Test
fun YamlNode_reproducer() {
    // https://yaml.org/spec/1.2.2/#10113-generic-string
    val originalYaml = """|"user":
                      |    "phone_with_prefix_double_quote": "+44123456"
                      |    "phone_with_prefix_single_quote": '+44123456'
                      |    "phone_with_prefix_str_tag": !!str "+44123456"
                      |    "phone_without_prefix": "44123456"
                      |""".trimMargin()

    val yaml = Yaml(
        configuration = YamlConfiguration(
            singleLineStringStyle = SingleLineStringStyle.DoubleQuoted,
            ambiguousQuoteStyle = AmbiguousQuoteStyle.DoubleQuoted,
        )
    )
    val yamlNode = yaml.parseToYamlNode(originalYaml)

    val encodedYaml = yaml.encodeToString(yamlNode)

    // "phone_with_prefix_double_quote": 44123456
    // "phone_with_prefix_single_quote": 44123456
    // "phone_with_prefix_str_tag": !!str '44123456'
    // "phone_without_prefix": 44123456
    expect(encodedYaml).toEqual(originalYaml)
}

Expected behaviour

Quoted strings kept as is, not losing content,
or !!str tag allows you to enforce it.

Actual behaviour

  1. Type is lost (quoted string becomes a number).
  2. String's content is modified

Version information

0.92.0

Any other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions