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

Empty dictionaries of certain types throw an error when decoding #32

Open
3 of 12 tasks
mkeiser opened this issue Jan 8, 2024 · 0 comments
Open
3 of 12 tasks

Empty dictionaries of certain types throw an error when decoding #32

mkeiser opened this issue Jan 8, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@mkeiser
Copy link

mkeiser commented Jan 8, 2024

Expected Behavior

Some empty dictionaries that have been encoded with CBOREncoder throw a type mismatch error when the data is decoded again with CBORDecoder.
To me this seems like a relatively severe bug.

Actual Behavior

See provided test methods.

Steps To Reproduce

Test methods I added to CBORDecoderTests. The first one currently fails, the second one succeeds.

    /// Fails!
    func testEmptyDictionaryRoundTripUInt64Key() throws {
        let dict = [UInt64: String]()
        let data = try CBOREncoder().encode(dict)
        let dict2: [UInt64: String] = try CBORDecoder().decode(from: data)
        XCTAssertEqual(dict, dict2)
    }

    /// Succeeds
    func testEmptyDictionaryRoundTripIntKey() throws {
        let dict = [Int: String]()
        let data = try CBOREncoder().encode(dict)
        let dict2: [Int: String] = try CBORDecoder().decode(from: data)
        XCTAssertEqual(dict, dict2)
    }

Other types fail too, for example dictionaries with Int32 keys.

Project Version

6fbd643

The OS/Variant where this issue occurs.

  • iOS
  • macOS
  • tvOS
  • watchOS
  • Mac Catalyst
  • Other (Please specify in "Additional Context" section)

The version of Xcode that was used when this issue appeared.

15.0.1 (15A507)

What was the environment in which the issue appeared?

  • CBORCoding.xcodeproj
  • Package.swift
  • Carthage
  • CocoaPods
  • Swift Package Manager
  • Other (Please specify in "Additional Context" section)

Additional Context

No response

@mkeiser mkeiser added the bug Something isn't working label Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants