Skip to content

Commit b7ca924

Browse files
committed
Remove lat & long RegEx check
and let the Uber API handle it reliably
1 parent 058063f commit b7ca924

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

lib/Uber.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,6 @@ Uber.prototype.get = function get(options, callback) {
203203
return this;
204204
};
205205

206-
Uber.prototype.validateCoordinates = function validateCoordinates(lat, lon) {
207-
if (!lat || !lon) {
208-
return false;
209-
}
210-
// use regex to check for validaty of latitude and longitude
211-
var location = lat + ', ' + lon;
212-
// taken from: http://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates
213-
var locationReg = new RegExp(/[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)/);
214-
215-
return locationReg.exec(location);
216-
};
217-
218206
Uber.prototype.isNumeric = function isNumeric(input) {
219207
return (!input || isNaN(input)) ? false : true;
220208
};

lib/resources/Estimates.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Estimates.prototype.getPriceForRoute = function getPriceForRoute(startLat,
1616
seats = 2;
1717
}
1818

19-
if (!this._uber.validateCoordinates(startLat, startLon)) {
19+
if (!startLat || !startLon) {
2020
return callback(new Error('Invalid starting point latitude & longitude'));
2121
}
2222

23-
if (!this._uber.validateCoordinates(endLat, endLon)) {
23+
if (!endLat || !endLon) {
2424
return callback(new Error('Invalid ending point latitude & longitude'));
2525
}
2626

@@ -46,7 +46,7 @@ Estimates.prototype.getETAForLocation = function getETAForLocation(lat, lon, id,
4646
id = undefined;
4747
}
4848

49-
if (!lat || !lon || !this._uber.validateCoordinates(lat, lon)) {
49+
if (!lat || !lon) {
5050
return callback(new Error('Invalid latitude & longitude'));
5151
}
5252

lib/resources/Products.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function Products(uber) {
88
module.exports = Products;
99

1010
Products.prototype.getAllForLocation = function getAllForLocation(lat, lon, callback) {
11-
if (!lat || !lon || !this._uber.validateCoordinates(lat, lon)) {
11+
if (!lat || !lon) {
1212
return callback(new Error('Invalid latitude & longitude'));
1313
}
1414

test/estimates.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ describe('Price', function() {
7575
});
7676
});
7777

78+
it('should return error if start point lat and lon are invalid', function(done) {
79+
uber.estimates.getPriceForRoute(null, null, 3.1357, 101.6880, function(err, res) {
80+
err.message.should.equal('Invalid starting point latitude & longitude');
81+
done();
82+
});
83+
});
84+
7885
it('should return error if end point lat and lon are invalid', function(done) {
79-
uber.estimates.getPriceForRoute(3.1357, 101.6880, -91.1357, 181.6880, function(err, res) {
86+
uber.estimates.getPriceForRoute(3.1357, 101.6880, null, null, function(err, res) {
8087
err.message.should.equal('Invalid ending point latitude & longitude');
8188
done();
8289
});

0 commit comments

Comments
 (0)