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

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

Closed
norio-nomura opened this issue Jan 28, 2018 · 0 comments · Fixed by #101
Closed

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

norio-nomura opened this issue Jan 28, 2018 · 0 comments · Fixed by #101
Labels

Comments

@norio-nomura
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant