Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

The UserController::update() method allowed empty strings from POST to overwrite valid credentials because $_POST['username'] ?? $user->getUsername() treats empty string as a valid value.

Changes

  • Added null checks to distinguish between omitted fields and empty submissions
  • Trim and cast input values before validation
  • Reject updates with empty username or email, redirect with error message
  • Preserve existing user data when fields are not in POST payload
// Before
$username = $_POST['username'] ?? $user->getUsername();
$email = $_POST['email'] ?? $user->getEmail();

// After
$usernameInput = $_POST['username'] ?? null;
$emailInput = $_POST['email'] ?? null;

$username = $usernameInput !== null ? trim( (string)$usernameInput ) : $user->getUsername();
$email = $emailInput !== null ? trim( (string)$emailInput ) : $user->getEmail();

if( $username === '' || $email === '' )
{
    $this->redirect( 'admin_users_edit', ['id' => $id], ['error', 'Username and email are required'] );
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: ljonesfl <1099983+ljonesfl@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on code refactoring and additional tests Add validation to prevent empty username/email in UserController update Nov 11, 2025
Copilot AI requested a review from ljonesfl November 11, 2025 23:38
Copilot finished work on behalf of ljonesfl November 11, 2025 23:38
@ljonesfl ljonesfl marked this pull request as ready for review November 11, 2025 23:45
@ljonesfl ljonesfl merged commit 3c1939b into feature/refactoring Nov 11, 2025
2 checks passed
@ljonesfl ljonesfl deleted the copilot/sub-pr-14 branch November 11, 2025 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants