Skip to content

null/~/NULL/Null parsed as strings, not nil #157

@finestructure

Description

@finestructure

I'm probably just holding it wrong but when I try to decode yml values with nil values - which I believe are represented as null | ~ | NULL | Null in yml - I get the corresponding Strings back and not nil:

    func test_null_yml() throws {
        let s = """
              n1: ~
              n2: null
              n3: NULL
              n4: Null
              n5:
            """
        struct Test: Decodable {
            let n1: String?
            let n2: String?
            let n3: String?
            let n4: String?
            let n5: String?
        }
        let t = try YAMLDecoder().decode(Test.self, from: s)
        XCTAssertNil(t.n1)  // XCTAssertNil failed: "~"
        XCTAssertNil(t.n2)  // XCTAssertNil failed: "null"
        XCTAssertNil(t.n3)  // XCTAssertNil failed: "NULL"
        XCTAssertNil(t.n4)  // XCTAssertNil failed: "Null"
        XCTAssertNil(t.n5)  // XCTAssertNil failed: ""
    }

This is with swift-4.2.1 and Yams

          "revision": "26ab35f50ea891e8edefcc9d975db2f6b67e1d68",
          "version": "1.0.1"

I see references to all these null tags in

XCTAssertEqual(resolver.resolveTag(of: "null"), .str)
and so I'm wondering: is there something wrong with my test setup above? Or is this perhaps a 🐛?

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