Skip to content

Reject NaN and Inf in coordinate validators - #1836

Merged
aaronbrethorst merged 1 commit into
OneBusAway:mainfrom
Rucha0901:fix/coordinate-validators-nan-inf
Oct 30, 2026
Merged

aaronbrethorst merged 1 commit into
OneBusAway:mainfrom
Rucha0901:fix/coordinate-validators-nan-inf

Conversation

@Rucha0901

@Rucha0901 Rucha0901 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1835

What it does

Rejects NaN and Inf values in ValidateLatitude, ValidateLongitude, ValidateRadius, and ValidateSpan.

Root cause

Comparisons against NaN always evaluate to false, so NaN passed bounds checks. Radius and span validators also only checked for values below zero, allowing positive infinity to pass.

Testing

  • Test failing on main before this change: TestValidateLatitude, TestValidateLongitude, TestValidateRadius, and TestValidateSpan returned nil instead of an error for NaN and Inf inputs.
  • Manual check: Ran go test ./internal/utils/... and go vet, all tests pass.

Checklist

  • This PR addresses one issue.
  • It is under ~200 changed lines, or the description says why it can't be split.
  • This PR is not a bug fix, or the new or changed test fails on main and passes on this branch.
  • Each commit is one logical change with a clear message.
  • I did not hand-edit sqlc-generated files under gtfsdb/ (db.go, models.go, query.sql.go) or testdata/openapi.yml (synced from upstream).
  • This PR changes no handler, or handlers pass r.Context() to DB/service calls, not context.Background().
  • The response comparison above is filled in, or this PR doesn't change a Java-served response.
  • This PR adds no endpoint, or each new endpoint matches testdata/openapi.yml, has an issue open on OneBusAway/sdk-config, or is outside the SDK and the description says why.
  • I read every line of this diff and can explain it if asked.

Summary by CodeRabbit

  • Bug Fixes
    • Latitude and longitude validation now rejects NaN and infinite values while preserving the existing valid coordinate ranges.
    • Radius and span validation now rejects NaN and infinite values, as well as negative values.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 7c4f948e-bff2-43f8-9149-5b39ae0dd12c
Commits

Reviewing files that changed from the base of the PR and between 2385b31 and e83fee9.

Files selected for processing: 2
  • internal/utils/validation.go
  • internal/utils/validation_test.go

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 104e5b43-f9d0-4683-abbd-34bf54d0a747
Commits

Reviewing files that changed from the base of the PR and between 3b4448b and 2385b31.

Files selected for processing: 2
  • internal/utils/validation.go
  • internal/utils/validation_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The latitude, longitude, radius, and span validators now reject NaN and infinite values. Their existing bounds and error messages remain in place. Tests cover NaN and both infinities for all four validators.

Changes: Numeric validation

Layer / File(s) Summary
Non-finite validation and test coverage
internal/utils/validation.go, internal/utils/validation_test.go
The four validators reject NaN and infinite values. Tests cover these inputs and check error messages only when validation returns an error.

Priority: Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related issues

  • OneBusAway/maglev#1499 — The validators now reject non-finite values, addressing part of the issue’s strict-validation objective. The changes do not cover every endpoint gap described there.

Suggested reviewers: aaronbrethorst, arcoder181105

Merge Risk: Minimal · previous review 2385b

No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description identifies the issue, explains the root cause, documents testing, and completes the checklist. The response comparison section is omitted, which is appropriate because the changes do n…
Title check Passed The title clearly and concisely describes the main change: rejecting NaN and infinite values in coordinate validators.
Linked Issues check Passed Issue #1835 requires ValidateLatitude, ValidateLongitude, ValidateRadius, and ValidateSpan to return errors for NaN and infinite inputs. The diff from the merge base to head in internal/utils/validati…
Out of Scope Changes check Passed All changed code is in internal/utils/validation.go and internal/utils/validation_test.go. The validation.go change adds the math import and the NaN and Inf guards that issue #1835 requests. The valid…
Full details: Description check

Explanation

The description identifies the issue, explains the root cause, documents testing, and completes the checklist. The response comparison section is omitted, which is appropriate because the changes do not affect a Java-served response.

Full details: Linked Issues check

Explanation

Issue #1835 requires ValidateLatitude, ValidateLongitude, ValidateRadius, and ValidateSpan to return errors for NaN and infinite inputs. The diff from the merge base to head in internal/utils/validation.go adds math.IsNaN and math.IsInf(x, 0) checks to all four functions. math.IsInf(x, 0) covers both positive and negative infinity. The existing bounds checks are unchanged. The diff to internal/utils/validation_test.go adds NaN, +Inf, and -Inf cases for all four validators, as the issue proposes. The test loops now guard the error-message assertion, so a nil error does not cause a panic. Relevant behavior is established from the diff. I did not run the test suite. The PR description's claim that these tests failed on main is not verified here, but it does not affect the requirement assessment.

Full details: Out of Scope Changes check

Explanation

All changed code is in internal/utils/validation.go and internal/utils/validation_test.go. The validation.go change adds the math import and the NaN and Inf guards that issue #1835 requests. The validation_test.go change adds the math import, the NaN and Inf test cases for the four named validators, and the nil-safe error assertion guard in those test loops. The nil-safe guard supports the new cases and stays within the same validators. No unrelated files or behavior changes appear in the diff. The raw summary reports no changes to exported declarations, which is consistent with the diff.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The description follows the PR template.

@github-actions github-actions Bot added the follows-template The PR description follows the PR template label Oct 25, 2026

@aaronbrethorst aaronbrethorst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Rucha0901, this looks good. Guarding the validators directly is a sensible belt-and-braces fix, and the table cases cover NaN and both infinities for all four functions.

One thing worth knowing: over HTTP this doesn't change any response. ParseFloatParam and ParseRequiredFloatParam already turn NaN/Inf into an Invalid field value error and return 0 (that landed in #1490), so every caller of ValidateLocationParams hands it a finite number today. This makes the validators safe on their own if a future caller skips the parse helpers.

  • Small nit, not blocking: "radius must be non-negative" reads a little odd for +Inf or NaN. Something like "radius must be a finite, non-negative number" would be clearer, but fine to leave.

Signed-off-by: Rucha0901 <imt_2025071@iiitm.ac.in>
@aaronbrethorst
aaronbrethorst force-pushed the fix/coordinate-validators-nan-inf branch from 2385b31 to e83fee9 Compare October 30, 2026 04:28
@sonarqubecloud

Copy link
Copy Markdown

@aaronbrethorst
aaronbrethorst merged commit 002b0f1 into OneBusAway:main Oct 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

follows-template The PR description follows the PR template

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coordinate validators allow NaN and Inf values

2 participants