Skip to content

Commit

Permalink
Remove any trailing slash from application name (#368)
Browse files Browse the repository at this point in the history
* Correct operator

* Trim trailing slash from name

* remove method

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
jasonmccreary and taylorotwell authored Dec 6, 2024
1 parent 9fefd0c commit 54bd7c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->validateDatabaseOption($input);
$this->validateStackOption($input);

$name = $input->getArgument('name');
$name = mb_rtrim($input->getArgument('name'), '/\\');

$directory = $this->getInstallationDirectory($name);

Expand Down Expand Up @@ -810,7 +810,7 @@ protected function generateAppUrl($name)
*/
protected function getTld()
{
return $this->runOnValetOrHerd('tld') ?? 'test';
return $this->runOnValetOrHerd('tld') ?: 'test';
}

/**
Expand Down
26 changes: 26 additions & 0 deletions tests/NewCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ public function test_it_can_scaffold_a_new_laravel_app()
$this->assertFileExists($scaffoldDirectory.'/.env');
}

public function test_it_can_chops_trailing_slash_from_name()
{
$scaffoldDirectoryName = 'tests-output/trailing/';
$scaffoldDirectory = __DIR__.'/../'.$scaffoldDirectoryName;

if (file_exists($scaffoldDirectory)) {
if (PHP_OS_FAMILY == 'Windows') {
exec("rd /s /q \"$scaffoldDirectory\"");
} else {
exec("rm -rf \"$scaffoldDirectory\"");
}
}

$app = new Application('Laravel Installer');
$app->add(new NewCommand);

$tester = new CommandTester($app->find('new'));

$statusCode = $tester->execute(['name' => $scaffoldDirectoryName], ['interactive' => false]);

$this->assertSame(0, $statusCode);
$this->assertDirectoryExists($scaffoldDirectory.'/vendor');
$this->assertFileExists($scaffoldDirectory.'/.env');
$this->assertStringContainsStringIgnoringLineEndings('APP_URL=http://tests-output/trailing.test', file_get_contents($scaffoldDirectory.'/.env'));
}

public function test_on_at_least_laravel_11()
{
$command = new NewCommand;
Expand Down

0 comments on commit 54bd7c9

Please sign in to comment.