Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/lib/isLatLong.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assertString from './util/assertString';
import merge from './util/merge';
import includes from './util/includesString';

const lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/;
const long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
Expand All @@ -16,8 +15,8 @@ export default function isLatLong(str, options) {
assertString(str);
options = merge(options, defaultLatLongOptions);

if (!includes(str, ',')) return false;
const pair = str.split(',');
if (pair.length !== 2) return false;
if ((pair[0].startsWith('(') && !pair[1].endsWith(')'))
|| (pair[1].endsWith(')') && !pair[0].startsWith('('))) return false;

Expand Down
27 changes: 27 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12856,6 +12856,33 @@ describe('Validators', () => {
});
});

it('should reject extra decimal LatLong components', () => {
test({
validator: 'isLatLong',
invalid: [
'0,0,',
'0,0,0',
'0,0,garbage',
'0, 0, 0, 0',
'(0, 0),',
'(0, 0),garbage',
],
});
});

it('should reject extra DMS LatLong components', () => {
test({
validator: 'isLatLong',
args: [{ checkDMS: true }],
invalid: [
'40° 26′ 46″ N, 79° 58′ 56″ W,',
'40° 26′ 46″ N, 79° 58′ 56″ W,0',
'40° 26′ 46″ N, 79° 58′ 56″ W,garbage',
'40° 26′ 46″ N, 79° 58′ 56″ W,0,0',
],
});
});

it('should validate postal code', () => {
const fixtures = [
{
Expand Down
Loading