Skip to content

fix(isLatLong): reject extra comma-separated segments - #2978

Open
TheFootlessBird wants to merge 1 commit into
validatorjs:masterfrom
TheFootlessBird:devin/1796085738-latlong-extra-segments
Open

TheFootlessBird wants to merge 1 commit into
validatorjs:masterfrom
TheFootlessBird:devin/1796085738-latlong-extra-segments

Conversation

@TheFootlessBird

Copy link
Copy Markdown

Reject latitude/longitude strings that contain extra comma-separated segments instead of silently ignoring everything after the longitude.

What is broken

isLatLong is documented to validate the format lat,long or lat, long. The implementation split the input on commas but validated only pair[0] and pair[1]. Because the number of segments was never checked, trailing input was discarded.

For example, these strings were accepted before this change:

validator.isLatLong('0,0,0'); // true
validator.isLatLong('10,10,unexpected'); // true
validator.isLatLong('40° 26′ 46″ N, 79° 58′ 56″ W,unexpected', { checkDMS: true }); // true

They are not valid coordinates in the documented two-part lat,long format, so they should return false.

Root cause and fix

String.prototype.split(',') preserves every comma-separated segment, but the validator never verified that exactly two segments existed. This PR adds that check before validating the latitude and longitude. It is a minimal root-cause fix: it does not change validation of either coordinate component and only rejects inputs whose top-level shape is not a single latitude/longitude pair.

Verification

The new regression tests fail against the unchanged implementation:

322 passing
1 failing
Error: validator.isLatLong("0,0,0") passed but should have failed

With the fix, the full local validation suite passes:

323 passing
Statements: 100%
Branches: 97.16%
Functions: 100%
Lines: 100%

The command run was npm test, which also rebuilt the distributions and ran ESLint.

The documented accepted structure is the existing README contract: lat,long or lat, long. No external format reference is needed because this PR enforces that existing documented contract rather than changing coordinate syntax.

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 00:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (32898cc).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2978   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2600    +1     
  Branches       658       659    +1     
=========================================
+ Hits          2599      2600    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants