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

Prevent crash when decoding case of malformed sequence of strings in a mapping #95

Closed
wants to merge 1 commit into from

Conversation

dcutting
Copy link

I had a case of malformed input that crashed the Decoder when using a Codable struct.

Given a struct like this:

struct Sample: Codable {
  let values: [String]
}

data like this would decode correctly:

values:
- hello

but data like this would crash:

values:
- hello:

It seems to be because it's looking for a mapping but not finding one and that case is not handled, so the subsequent assertion fails. This PR avoids the crash by returning nil instead.

I'm not sure this is the right way to handle it (or even a good way), but at least it prevents the crash in my use case.

Thanks for creating this pod!

@norio-nomura
Copy link
Collaborator

Thank you for PR! But we already received another PR #94 today that fixes the same issue.
So close this.
Thank you again! 🙏

norio-nomura added a commit that referenced this pull request Feb 17, 2018
norio-nomura added a commit that referenced this pull request Feb 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants