Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,26 @@ private function uploadTableCsv($doUnicode)
], 423);
}

if (empty($reader)) {
return $this->sendError([
'data' => [
'errors' => array(),
'message' => __('The imported CSV file is empty.', 'ninja-tables')
]
], 423);
}
Comment on lines +106 to +113

Choose a reason for hiding this comment

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

Action required

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


$header = array_shift($reader);

if (empty($header) || !is_array($header)) {
return $this->sendError([
'data' => [
'errors' => array(),
'message' => __('The imported CSV file is missing a header row.', 'ninja-tables')
]
], 423);
}

$tableId = $this->createTable(array(
'post_title' => $fileName,
'post_content' => '',
Expand Down Expand Up @@ -426,6 +444,13 @@ public function extracted($data)

$data = ninja_tables_sanitize_array($data);

if (empty($data)) {
return $this->sendError([
'errors' => array(),
'message' => __('The imported file does not contain any rows.', 'ninja-tables')
], 423);
}

$tableId = $this->savedDragAndDropTable($data, $fileName);

return $this->sendSuccess([
Expand Down