Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Ensure port is a string when creating credentials file for Postgres #203

Merged

Conversation

RVxLab
Copy link
Contributor

@RVxLab RVxLab commented Dec 23, 2023

This PR ensures that the port is a string when creating the credentials file contents when using Postgres.

In strict mode, since port is an int, an error occurs when you try to dump a database:


   TypeError

  str_replace(): Argument #3 ($subject) must be of type array|string, int given

  at vendor/spatie/db-dumper/src/Databases/PostgreSql.php:95
     91▕     }
     92▕
     93▕     protected function escapeCredentialEntry($entry): string
     94▕     {
  ➜  95▕         $entry = str_replace('\\', '\\\\', $entry);
     96▕         $entry = str_replace(':', '\\:', $entry);
     97▕
     98▕         return $entry;
     99▕     }

      +5 vendor frames

  6   [internal]:0
      Spatie\Backup\Tasks\Backup\BackupJob::Spatie\Backup\Tasks\Backup\{closure}(Object(Spatie\DbDumper\Databases\PostgreSql), "pgsql")
      +19 vendor frames

  26  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

For MySQL this isn't happening since the port gets coerced into a string through string interpolation.

By casting the port into a string, the error goes away.

@freekmurze freekmurze merged commit 59beef7 into spatie:main Dec 25, 2023
7 checks passed
@freekmurze
Copy link
Member

Thanks!

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