Repository navigation
Reject NaN and Inf in coordinate validators - #1836
Conversation
|
Warning Review limit reachedYou'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. View limit details
No actionable comments were generated in the recent review.
|
| 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:
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: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
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
#1835requires 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
#1835requests. 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.
Comment @coderabbitai help to get the list of available commands.
|
The description follows the PR template. |
aaronbrethorst
left a comment
There was a problem hiding this comment.
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
+InforNaN. 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>
2385b31 to
e83fee9
Compare
|



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
mainbefore this change:TestValidateLatitude,TestValidateLongitude,TestValidateRadius, andTestValidateSpanreturnednilinstead of an error forNaNandInfinputs.go test ./internal/utils/...andgo vet, all tests pass.Checklist
mainand passes on this branch.gtfsdb/(db.go,models.go,query.sql.go) ortestdata/openapi.yml(synced from upstream).r.Context()to DB/service calls, notcontext.Background().testdata/openapi.yml, has an issue open on OneBusAway/sdk-config, or is outside the SDK and the description says why.Summary by CodeRabbit