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

Mapbox Directions API OSRM Name Fix #222

Merged
merged 7 commits into from
Dec 8, 2017
Merged

Conversation

JThramer
Copy link
Contributor

@JThramer JThramer commented Dec 7, 2017

This mostly fixes issue mapbox/mapbox-navigation-ios#921, where an empty string is bypassing the CLGeocoder and causing the coordinate logic to trigger (which does test for empty string -- a bug, but moot because it's being removed anyway). This change fixes this issue and makes sure that waypoint.name == nil when the Mapbox Directions API does not return an OSRM name for the waypoint.

  • Fixing issue where querying a nonexistent waypoints[n].name keypath in the result json will produce "" instead of the expected nil. Adding logic to compensate for this.

ToDo:

  • Add Test that covers MBRouteOptions.response(from:) and tests this edge-case
  • isNotEmpty / nonEmptyString extension and usage

/cc @bsudekum @1ec5 @frederoni

… in the result `json` will produce `""` instead of the expected `nil`. Adding logic to compensate for this.
@JThramer JThramer added the bug label Dec 7, 2017
@bsudekum
Copy link

bsudekum commented Dec 7, 2017

Would it be possible to add a test case?

let location = api["location"] as! [Double]
let coordinate = CLLocationCoordinate2D(geoJSON: location)
return Waypoint(coordinate: coordinate, name: local.name ?? api["name"] as? String)
let possibleAPIName = api["name"] as? String
let apiName = (possibleAPIName?.isEmpty ?? true) ? nil : possibleAPIName!
Copy link
Contributor

@1ec5 1ec5 Dec 7, 2017

Choose a reason for hiding this comment

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

Core Navigation extends String with nonEmptyString, which is pretty convenient for situations like this. Feel free to copy it here, but make it internal, because MapboxDirections.swift shouldn’t be in the business of providing string processing helpers to clients.

@JThramer
Copy link
Contributor Author

JThramer commented Dec 8, 2017

I think #217 should be closed as well after this is merged and verified.

@bsudekum
Copy link

bsudekum commented Dec 8, 2017

@JThramer mind checking out the test failure:

❌  /Users/vagrant/git/MapboxDirections/MBRouteOptions.swift:487:46: value of type 'String' has no member 'nonEmptyString'
                let apiName = possibleAPIName?.nonEmptyString
                              ~~~~~~~~~~~~~~~^ ~~~~~~~~~~~~~~

import Foundation

extension String {
var isNotEmpty: Bool { return !isEmpty }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably a bit extreme. For one thing, it’s more verbose than using the ! operator, which is more versatile than hard-coding negative versions of Boolean properties.

@JThramer JThramer merged commit cd72999 into master Dec 8, 2017
@JThramer JThramer deleted the jerrad/osrm-name-nil branch December 8, 2017 22:28
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 this pull request may close these issues.

None yet

3 participants