Skip to content

Commit 47f3492

Browse files
ezkemboiprofnandaa
authored andcommitted
fix(isLatLong): fix bug on brackets mismatch (#1074)
- when lat starts with (, it makes it a true latitude. - Closes #929
1 parent 1ce76a1 commit 47f3492

6 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎lib/isLatLong.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function _default(str) {
1616
(0, _assertString.default)(str);
1717
if (!str.includes(',')) return false;
1818
var pair = str.split(',');
19+
if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
1920
return lat.test(pair[0]) && long.test(pair[1]);
2021
}
2122

‎lib/isMobilePhone.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var phones = {
6868
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
6969
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
7070
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
71-
'ja-JP': /^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,
71+
'ja-JP': /^(\+?81|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
7272
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
7373
'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
7474
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,

‎src/lib/isLatLong.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ export default function (str) {
77
assertString(str);
88
if (!str.includes(',')) return false;
99
const pair = str.split(',');
10+
if ((pair[0].startsWith('(') && !pair[1].endsWith(')'))
11+
|| (pair[1].endsWith(')') && !pair[0].startsWith('('))) return false;
1012
return lat.test(pair[0]) && long.test(pair[1]);
1113
}

‎test/validators.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6529,6 +6529,8 @@ describe('Validators', () => {
65296529
'-112.96381, -160.96381',
65306530
'-90., -180.',
65316531
'+90.1, -180.1',
6532+
'(-17.738223, 85.605469',
6533+
'0.955766, -19.863281)',
65326534
'+,-',
65336535
'(,)',
65346536
',',

‎validator.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ var phones = {
13991399
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
14001400
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
14011401
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
1402-
'ja-JP': /^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,
1402+
'ja-JP': /^(\+?81|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
14031403
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
14041404
'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
14051405
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
@@ -1739,6 +1739,7 @@ var isLatLong = function (str) {
17391739
assertString(str);
17401740
if (!str.includes(',')) return false;
17411741
var pair = str.split(',');
1742+
if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
17421743
return lat.test(pair[0]) && _long.test(pair[1]);
17431744
};
17441745

‎validator.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)