Skip to content

Commit

Permalink
fix(isLatLong): fix bug on isLatLang
Browse files Browse the repository at this point in the history
- when lat starts with (, it makes it a true latitude.
- Closes #929
  • Loading branch information
ezkemboi committed Jul 29, 2019
1 parent 54bf8c4 commit 6a1d78d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/isLatLong.js
Expand Up @@ -16,6 +16,7 @@ function _default(str) {
(0, _assertString.default)(str);
if (!str.includes(',')) return false;
var pair = str.split(',');
if (pair[0].charAt(0) === '(' && pair[1].charAt(pair[1].length - 1) !== ')' || pair[1].charAt(pair[1].length - 1) === ')' && pair[0].charAt(0) !== '(') return false;
return lat.test(pair[0]) && long.test(pair[1]);
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib/isLatLong.js
Expand Up @@ -7,5 +7,9 @@ export default function (str) {
assertString(str);
if (!str.includes(',')) return false;
const pair = str.split(',');
if (
(pair[0].charAt(0) === '(' && pair[1].charAt(pair[1].length - 1) !== ')') ||
(pair[1].charAt(pair[1].length - 1) === ')' && pair[0].charAt(0) !== '(')
) return false;
return lat.test(pair[0]) && long.test(pair[1]);
}
2 changes: 2 additions & 0 deletions test/validators.js
Expand Up @@ -6523,6 +6523,8 @@ describe('Validators', () => {
'-112.96381, -160.96381',
'-90., -180.',
'+90.1, -180.1',
'(-17.738223, 85.605469',
'0.955766, -19.863281)',
'+,-',
'(,)',
',',
Expand Down
1 change: 1 addition & 0 deletions validator.js
Expand Up @@ -1739,6 +1739,7 @@ var isLatLong = function (str) {
assertString(str);
if (!str.includes(',')) return false;
var pair = str.split(',');
if (pair[0].charAt(0) === '(' && pair[1].charAt(pair[1].length - 1) !== ')' || pair[1].charAt(pair[1].length - 1) === ')' && pair[0].charAt(0) !== '(') return false;
return lat.test(pair[0]) && _long.test(pair[1]);
};

Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 6a1d78d

Please sign in to comment.