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

Handle nil content value #289

Merged
merged 4 commits into from
Jun 12, 2018
Merged

Handle nil content value #289

merged 4 commits into from
Jun 12, 2018

Conversation

fractalwrench
Copy link
Contributor

@fractalwrench fractalwrench commented Jun 11, 2018

Goal

The notifier currently assumes that the "value" key in notable_addresses data is non-null, whereas this is not necessarily the case, which can lead to an NSInvalidArgumentException.

This change adds unit test coverage for this method, and ensures that it can handle any of the items in the dictionary being null.

Changeset

Added

Unit Tests which cover behaviour of the class.

Removed

Changed

Skip iteration if the contentValue is nil.

Review

For the submitter, initial self-review:

  • Commented on code changes inline explain the reasoning behind the approach
  • Reviewed the test cases added for completeness and possible points for discussion
  • A changelog entry was added for the goal of this pull request
  • Check the scope of the changeset - is everything in the diff required for the pull request?
  • This pull request is ready for:
    • Initial review of the intended approach, not yet feature complete
    • Structural review of the classes, functions, and properties modified
    • Final review

For the pull request reviewer(s), this changeset has been reviewed for:

  • Consistency across platforms for structures or concepts added or modified
  • Consistency between the changeset and the goal stated above
  • Internal consistency with the rest of the library - is there any overlap between existing interfaces and any which have been added?
  • Usage friction - is the proposed change in usage cumbersome or complicated?
  • Performance and complexity - are there any cases of unexpected O(n^3) when iterating, recursing, flat mapping, etc?
  • Concurrency concerns - if components are accessed asynchronously, what issues will arise
  • Thoroughness of added tests and any missing edge cases
  • Idiomatic use of the language

It appears that "value" can be nil in some situations, which could lead to an nsexception being
raised on subsequent operations. this change skips the iteration if this is the case.
@fractalwrench fractalwrench requested a review from a team June 11, 2018 10:16
if ([self isReservedWord:contentValue]) {
reservedWord = contentValue;
} else if (!([[contentValue componentsSeparatedByString:@"/"] count] > 2)) {
} else if ([[contentValue componentsSeparatedByString:@"/"] count] <= 2) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change just simplifies the condition to make it more readable

Copy link

@martin308 martin308 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code change itself looks good to me.

It's not super obvious to me that there is a test case that covers the specific situation where contentValue is nil. Should there be a test where the value for the key "value" is explicitly set as nil?

@fractalwrench
Copy link
Contributor Author

I've added both an implicit and explicit test case for where "value" can be nil. I've also added a type check as the original issue occurred if [NSNull null] was present, as this wouldn't evaluate to false but is nil.

@@ -630,9 +630,12 @@ + (instancetype)errorDataFromThreads:(NSArray *)threads {
}
NSString *contentValue = data[@"value"];

if (!contentValue) {
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCDFAInspection"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suppresses warnings on a redundant nsstring type check, which actually isn't redundant when contentValue is NSNull

@fractalwrench fractalwrench merged commit 5aa9e44 into next Jun 12, 2018
@fractalwrench fractalwrench deleted the handle-nil-content-value branch June 12, 2018 09:15
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.

3 participants