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

Inconsistent floating point conversion behavior between GET and POST requests under iOS 11.x #2534

Open
lhasiuk opened this issue Apr 17, 2018 · 0 comments

Comments

@lhasiuk
Copy link

lhasiuk commented Apr 17, 2018

The following code snippet reveals interesting behavior under iOS 11 (but not iOS 10):

        double lat = 47.6024947;
        double lon = -122.3379909;

        NSDictionary *params = @{ @"lat": @(lat) , @"lon": @(lon) }];
        NSMutableURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodPOST path:@"/path" parameters:params];
        NSLog(@"%@: %@, body %@", request.HTTPMethod, request.URL.absoluteString, [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding]);
        request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:@"/path" parameters:params];
        NSLog(@"%@: %@", request.HTTPMethod, request.URL.absoluteString);

Result:
POST: https://api.host.com/path, body {"lat":47.602494700000001,"lon":-122.33799089999999}
GET: https://api.host.com/path?lat=47.6024947&lon=-122.3379909

Under iOS 10.x the POST body's "lat" and "lon" values match those seen in the GET URI and the values originally assigned to the "lat" and "lon" doubles, i.e.:
POST: https://api.host.com/path, body {"lat":47.6024947,"lon":-122.3379909}
GET: https://api.host.com/path?lat=47.6024947&lon=-122.3379909

I have a workaround where I use NSDecimalNumbers in the params dictionary, instead of NSNumbers, but the behavior still seems wrong to me. Whatever conversion method is used in building the JSON should match what's used when building the URI parameters.

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

No branches or pull requests

1 participant