From b05ebfedeb7e0d6b37b17c6525b52dc59b7f058f Mon Sep 17 00:00:00 2001 From: Guo Jiarui <799423879@qq.com> Date: Mon, 7 Sep 2026 11:22:46 +0800 Subject: [PATCH 1/2] fix(isLatLong): reject extra coordinate components --- src/lib/isLatLong.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/isLatLong.js b/src/lib/isLatLong.js index c4e622753..b0fc05230 100644 --- a/src/lib/isLatLong.js +++ b/src/lib/isLatLong.js @@ -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+)?)\)?$/; @@ -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; From fd05da79e532eb787809a0c71071b2fda8364906 Mon Sep 17 00:00:00 2001 From: Guo Jiarui <799423879@qq.com> Date: Mon, 7 Sep 2026 11:23:37 +0800 Subject: [PATCH 2/2] test(isLatLong): cover extra decimal and DMS components --- test/validators.test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..d8b6bef53 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -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 = [ {