fix: validate recordId before split in googledns deleteRecord (#454)#471
fix: validate recordId before split in googledns deleteRecord (#454)#471nikos1005 wants to merge 1 commit into
Conversation
Greptile SummaryAdds a pre-split guard to
Confidence Score: 4/5The change is a small, focused guard that improves error messaging and prevents crashes on bad input; it does not alter the happy path. The guard correctly handles the most common invalid input cases at runtime. Two edge cases remain: the validation accepts recordId values with empty segments (e.g. packages/dns/googledns/src/index.ts — the validation condition and whether it truly resolves the downstream TypeScript errors. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[deleteRecord zoneId recordId config] --> B{recordId is not string OR has no slash}
B -- Yes --> C[throw Error Invalid recordId]
B -- No --> D[split recordId into type and name]
D --> E[listRecords then filter by type and name]
E --> F{existing.length === 0}
F -- Yes --> G[return early]
F -- No --> H[POST changes with deletions]
H --> I{res.ok or 404}
I -- No --> J[throw Error deleteRecord status]
I -- Yes --> K[done]
|
| if (typeof recordId !== 'string' || !recordId.includes('/')) { | ||
| throw new Error(`Invalid recordId: ${recordId}. Expected format: "<type>/<FQDN>"`); | ||
| } |
There was a problem hiding this comment.
Empty segment edge cases pass validation
recordId.includes('/') accepts values like /example.com. or A/ — both contain a / but produce an empty type or name after the split. An empty type silently matches no records and the function returns without error; an empty name produces fqdn = '.' which is syntactically wrong and may generate a confusing API error. Adding a stricter pattern check would catch these at the validation boundary.
| if (typeof recordId !== 'string' || !recordId.includes('/')) { | |
| throw new Error(`Invalid recordId: ${recordId}. Expected format: "<type>/<FQDN>"`); | |
| } | |
| if (typeof recordId !== 'string' || !/^[^/]+\/[^/]+/.test(recordId)) { | |
| throw new Error(`Invalid recordId: ${recordId}. Expected format: "<type>/<FQDN>"`); | |
| } |
Summary
Add validation for
recordIdbefore destructuring split to avoid TS18048 undernoUncheckedIndexedAccess.Fixes #454