Skip to content

Commit

Permalink
fix(isLatLong): fix bug on brackets mismatch (#1074)
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 authored and profnandaa committed Aug 2, 2019
1 parent 1ce76a1 commit 47f3492
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 3 deletions.
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].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
return lat.test(pair[0]) && long.test(pair[1]);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/isMobilePhone.js
Expand Up @@ -68,7 +68,7 @@ var phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
'ja-JP': /^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,
'ja-JP': /^(\+?81|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/isLatLong.js
Expand Up @@ -7,5 +7,7 @@ export default function (str) {
assertString(str);
if (!str.includes(',')) return false;
const pair = str.split(',');
if ((pair[0].startsWith('(') && !pair[1].endsWith(')'))
|| (pair[1].endsWith(')') && !pair[0].startsWith('('))) return false;
return lat.test(pair[0]) && long.test(pair[1]);
}
2 changes: 2 additions & 0 deletions test/validators.js
Expand Up @@ -6529,6 +6529,8 @@ describe('Validators', () => {
'-112.96381, -160.96381',
'-90., -180.',
'+90.1, -180.1',
'(-17.738223, 85.605469',
'0.955766, -19.863281)',
'+,-',
'(,)',
',',
Expand Down
3 changes: 2 additions & 1 deletion validator.js
Expand Up @@ -1399,7 +1399,7 @@ var phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
'ja-JP': /^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,
'ja-JP': /^(\+?81|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
Expand Down Expand Up @@ -1739,6 +1739,7 @@ var isLatLong = function (str) {
assertString(str);
if (!str.includes(',')) return false;
var pair = str.split(',');
if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) 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 47f3492

Please sign in to comment.