pr: [Nightly Fix] - Null Safety - Guard Empty Imports#4
pr: [Nightly Fix] - Null Safety - Guard Empty Imports#4jewel-claw wants to merge 1 commit intomasterfrom
Conversation
|
PR author is not in the allowed authors list. |
Review Summary by QodoGuard against empty imports and missing headers
WalkthroughsDescription• Add empty file validation in CSV importer before processing • Add missing header row validation in CSV importer • Add empty data guard in drag-and-drop import path • Prevent undefined offset access and invalid table creation Diagramflowchart LR
CSV["CSV Upload"] --> Parse["Parse CSV"]
Parse --> CheckEmpty["Check if empty"]
CheckEmpty -->|Empty| Error1["Return error: empty file"]
CheckEmpty -->|Not empty| ExtractHeader["Extract header"]
ExtractHeader --> CheckHeader["Check header exists"]
CheckHeader -->|Missing| Error2["Return error: missing header"]
CheckHeader -->|Valid| CreateTable["Create table"]
DragDrop["Drag & Drop/URL Import"] --> GetData["Get data"]
GetData --> Sanitize["Sanitize data"]
Sanitize --> CheckRows["Check if has rows"]
CheckRows -->|Empty| Error3["Return error: no rows"]
CheckRows -->|Has rows| SaveTable["Save table"]
File Changes1. app/Http/Controllers/ImportController.php
|
Code Review by Qodo
1. CSV error response dropped
|
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Other Observations (not in diff)No issues found in unchanged code. Files Reviewed (1 file)
Code Quality AssessmentPositive changes:
Issue details: The new error responses at lines 107-112 and 118-123 wrap the error in a
Recommendation: Make the error response structure consistent across all validation checks - either all should have Review generated by Kilo Code Review |
| if (empty($reader)) { | ||
| return $this->sendError([ | ||
| 'data' => [ | ||
| 'errors' => array(), | ||
| 'message' => __('The imported CSV file is empty.', 'ninja-tables') | ||
| ] | ||
| ], 423); | ||
| } |
There was a problem hiding this comment.
1. Csv error response dropped 🐞 Bug ✓ Correctness
defaultImport() calls uploadTableCsv() without returning its WP_REST_Response, so the new sendError() returns for empty/header-missing CSVs are discarded and the handler continues to the generic “No appropriate driver found” response. This prevents the intended validation message from reaching clients and makes the new guards ineffective for user feedback.
Agent Prompt
### Issue description
`defaultImport()` calls the specific importer methods but does **not** `return` their responses. When `uploadTableCsv()` returns via `sendError()` (including the new empty/header checks), the response object is discarded and `defaultImport()` continues to send the generic fallback error.
### Issue Context
`sendError()` returns a `WP_REST_Response` and does not terminate execution. The REST router expects the controller method to return that response.
### Fix Focus Areas
- app/Http/Controllers/ImportController.php[28-58]
- app/Http/Controllers/ImportController.php[106-124]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
What
Why
Fix
Confidence
app/Http/Controllers/ImportController.phpwithphp -l