Skip to content

Commit

Permalink
Merge pull request #6917 from getkirby/fix/6489-server-software-too-long
Browse files Browse the repository at this point in the history
System view: ensure short server software name
  • Loading branch information
distantnative authored Jan 17, 2025
2 parents 9a070ec + 1d64546 commit cce3151
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/areas/system/views.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
[
'label' => I18n::translate('server'),
'value' => $system->serverSoftware() ?? '?',
'value' => $system->serverSoftwareShort() ?? '?',
'icon' => 'server'
]
];
Expand Down
10 changes: 10 additions & 0 deletions src/Cms/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ public function serverSoftware(): string
return $this->app->environment()->get('SERVER_SOFTWARE', '');
}

/**
* Returns the short version of the detected server software
* @since 4.6.0
*/
public function serverSoftwareShort(): string
{
$software = $this->serverSoftware();
return strtok($software, ' ');
}

/**
* Check for a writable sessions folder
*/
Expand Down
24 changes: 24 additions & 0 deletions tests/Cms/System/SystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,30 @@ public function testServerSoftwareInvalid()
$this->assertSame('', $system->serverSoftware());
}

/**
* @covers ::serverSoftwareShort
*/
public function testServerSoftwareShort()
{
$app = $this->app->clone([
'server' => [
'SERVER_SOFTWARE' => $software = 'nginx/1.25.4'
]
]);

$system = new System($app);
$this->assertSame($software, $system->serverSoftwareShort());

$app = $this->app->clone([
'server' => [
'SERVER_SOFTWARE' => $software = 'Apache/2.4.7 (Ubuntu)'
]
]);

$system = new System($app);
$this->assertSame('Apache/2.4.7', $system->serverSoftwareShort());
}

/**
* @covers ::accounts
* @covers ::content
Expand Down

0 comments on commit cce3151

Please sign in to comment.