Skip to content

Commit 54bd7c9

Browse files
Remove any trailing slash from application name (#368)
* Correct operator * Trim trailing slash from name * remove method --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 9fefd0c commit 54bd7c9

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/NewCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
159159
$this->validateDatabaseOption($input);
160160
$this->validateStackOption($input);
161161

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

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

@@ -810,7 +810,7 @@ protected function generateAppUrl($name)
810810
*/
811811
protected function getTld()
812812
{
813-
return $this->runOnValetOrHerd('tld') ?? 'test';
813+
return $this->runOnValetOrHerd('tld') ?: 'test';
814814
}
815815

816816
/**

tests/NewCommandTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,32 @@ public function test_it_can_scaffold_a_new_laravel_app()
3434
$this->assertFileExists($scaffoldDirectory.'/.env');
3535
}
3636

37+
public function test_it_can_chops_trailing_slash_from_name()
38+
{
39+
$scaffoldDirectoryName = 'tests-output/trailing/';
40+
$scaffoldDirectory = __DIR__.'/../'.$scaffoldDirectoryName;
41+
42+
if (file_exists($scaffoldDirectory)) {
43+
if (PHP_OS_FAMILY == 'Windows') {
44+
exec("rd /s /q \"$scaffoldDirectory\"");
45+
} else {
46+
exec("rm -rf \"$scaffoldDirectory\"");
47+
}
48+
}
49+
50+
$app = new Application('Laravel Installer');
51+
$app->add(new NewCommand);
52+
53+
$tester = new CommandTester($app->find('new'));
54+
55+
$statusCode = $tester->execute(['name' => $scaffoldDirectoryName], ['interactive' => false]);
56+
57+
$this->assertSame(0, $statusCode);
58+
$this->assertDirectoryExists($scaffoldDirectory.'/vendor');
59+
$this->assertFileExists($scaffoldDirectory.'/.env');
60+
$this->assertStringContainsStringIgnoringLineEndings('APP_URL=http://tests-output/trailing.test', file_get_contents($scaffoldDirectory.'/.env'));
61+
}
62+
3763
public function test_on_at_least_laravel_11()
3864
{
3965
$command = new NewCommand;

0 commit comments

Comments
 (0)