fix: 🐛 versions are parsed as integers instead of numbers#887
Open
fix: 🐛 versions are parsed as integers instead of numbers#887
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
1 issue found across 6 files
Confidence score: 3/5
- There is a concrete validation risk in
shared/api/common/queryHelpers.ts:queryNumberusesparseFloat, so malformed inputs like"1abc"can be accepted as valid numbers. - Because this is severity 7/10 with high confidence (9/10) and affects request parameter validation, it carries real user-impact/regression risk if merged as-is.
- This is likely fixable with stricter numeric parsing/checks, but until then the merge has moderate risk rather than being fully safe.
- Pay close attention to
shared/api/common/queryHelpers.ts- numeric query validation may incorrectly allow malformed values.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="shared/api/common/queryHelpers.ts">
<violation number="1" location="shared/api/common/queryHelpers.ts:125">
P1: `queryNumber` uses `parseFloat`, which accepts malformed numeric strings with trailing characters (e.g., `"1abc"`). This can let invalid query params pass validation as valid numbers.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| return val; | ||
| } | ||
| if (typeof val === "string") { | ||
| const parsed = Number.parseFloat(val); |
Contributor
There was a problem hiding this comment.
P1: queryNumber uses parseFloat, which accepts malformed numeric strings with trailing characters (e.g., "1abc"). This can let invalid query params pass validation as valid numbers.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At shared/api/common/queryHelpers.ts, line 125:
<comment>`queryNumber` uses `parseFloat`, which accepts malformed numeric strings with trailing characters (e.g., `"1abc"`). This can let invalid query params pass validation as valid numbers.</comment>
<file context>
@@ -96,3 +96,35 @@ export function queryInteger(options?: {
+ return val;
+ }
+ if (typeof val === "string") {
+ const parsed = Number.parseFloat(val);
+ return Number.isNaN(parsed) ? val : parsed;
+ }
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by cubic
Switch version handling to decimal numbers across API and UI, and add explicit variant schema for products. This unblocks plan variants on feat/plan-variants and removes the old auto-detection flow.
New Features
Bug Fixes
Written for commit 159fa97. Summary will update on new commits.
Greptile Summary
This PR fixes a bug where product version numbers were being parsed as integers (via
parseInt) instead of floating-point numbers, which prevented decimal versions (e.g.1.1,1.5) from being handled correctly across the API and frontend.Key changes:
parseIntreplaced withNumber.parseFloatinCusSearchService.tsandhandleGetCustomerProduct.tsto correctly preserve decimal version values when filtering and fetching customer products.parseInt(version, 10)replaced withparseFloat(version)inEditPlanHeader.tsxso the frontend version-change handler also handles decimal versions properly.queryNumberZod helper is added inqueryHelpers.ts, mirroring the existingqueryIntegerbut without the.int()constraint, enabling decimal query params for version fields.handleGetProductCount.tsandhandleGetProductInternal.tsswitch theirversionquery schema fromqueryIntegertoqueryNumber, aligning validation with the now-supported decimal version format.Confidence Score: 5/5
parseIntwithparseFloatpreserves integer-version queries while enabling decimal versions. The newqueryNumberhelper is a clean addition following established patterns. All modifications are backward-compatible.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["Query param: version string\n(e.g. '1', '1.5')"] --> B{Handler / Schema} B -->|"handleGetProductInternal\nhandleGetProductCount"| C["queryNumber()\nzod preprocess"] B -->|"handleGetCustomerProduct"| D["Number.parseFloat(version)"] B -->|"CusSearchService"| E["Number.parseFloat(version)"] B -->|"EditPlanHeader (frontend)"| F["parseFloat(version)"] C --> G["z.number() — allows decimals"] D --> H["Passed to ProductService.getFull()\nor productToCusProduct()"] E --> I["productVersionFilters object"] F --> J["setQueryStates({ version })"] G --> HLast reviewed commit: b040107
Context used:
dashboard- When generating the key changes section of the summary, please tag each change with one or many of t... (source)