Skip to content

subscript(string:) fails to lookup value if Node has non default Resolver #100

@norio-nomura

Description

@norio-nomura

Since tag of Node is resolved by Resolver, If Resolver is different, tag will also be different.

try Yams.compose(yaml: "200")!.tag                // tag:yaml.org,2002:int
try Yams.compose(yaml: "200", .basic)!.tag        // tag:yaml.org,2002:str

Yams uses not only values but also tags for checking equality of Node.

let node1 = try Yams.compose(yaml: "200")
let node2 = try Yams.compose(yaml: "200", .basic)
node1 == node2                                    // false

Since current implementation of subscript(string:) creates Node from String with default Resolver, if target Node has different Resolver, subscript will fail to lookup value.

Node("200").tag                                  // tag:yaml.org,2002:int
let yaml = "200: value"
let node3 = try Yams.compose(yaml: yaml)         // "200" is resolved to tag:yaml.org,2002:int
let key1 = Node("200", Tag(.int))
let key2 = Node("200", Tag(.str))
node3?[key1]?.string                             // "value"
node3?[key2]?.string                             // nil
node3?["200"]?.string                            // "value"
let node4 = try Yams.compose(yaml: yaml, .basic) // "200" is resolved to tag:yaml.org,2002:str
node4?[key1]?.string                             // nil
node4?[key2]?.string                             // "value"
node4?["200"]?.string                            // nil

This behavior causes the issue #99

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions