Skip to content

Commit

Permalink
Fixed detecting URL prefix during installation.
Browse files Browse the repository at this point in the history
  • Loading branch information
parpalak committed Aug 15, 2024
1 parent 9a1e052 commit 5273a5e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions _admin/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function generate_config_file ()
foreach (array('', '/?', '/index.php', '/index.php?') as $prefix) {
$url_prefix = $prefix;
$content = s2_get_remote_file($base_url.$url_prefix.'/this/URL/_DoEs_/_NoT_/_eXiSt', 1, false, 10, true);
if ($content !== null && str_contains($content['content'], '<meta name="Generator" content="S2" />')) {
if ($content !== null && str_contains($content['content'], '<meta name="Generator" content="S2">')) {
break;
}
}
Expand All @@ -80,7 +80,7 @@ function generate_config_file ()
}
else {
$content = s2_get_remote_file('https://'.substr($base_url, 7).$url_prefix.'/this/URL/_DoEs_/_NoT_/_eXiSt', 1, false, 10, true);
if ($content !== null && str_contains($content['content'], '<meta name="Generator" content="S2" />')) {
if ($content !== null && str_contains($content['content'], '<meta name="Generator" content="S2">')) {
$use_https = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions _include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ function error()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="Generator" content="S2"/>
<meta charset="utf-8">
<meta name="Generator" content="S2">
<title>Error - <?php echo s2_htmlencode(S2_SITE_NAME); ?></title>
<style>
body {
Expand Down
2 changes: 1 addition & 1 deletion _include/src/Template/HtmlTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function toHttpResponse(): Response

// Meta tags processing
$meta_tags = [
'<meta name="Generator" content="S2" />',
'<meta name="Generator" content="S2">',
];

if (!empty($this->page['meta_keywords'])) {
Expand Down
2 changes: 1 addition & 1 deletion _include/views/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html>
<head>
<meta charset="utf-8">
<meta name="Generator" content="S2" />
<meta name="Generator" content="S2">
<title>Error - <?php echo defined('S2_SITE_NAME') ? s2_htmlencode(S2_SITE_NAME) : 'S2'; ?></title>
<style>
body {
Expand Down
7 changes: 7 additions & 0 deletions _tests/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public function install(string $userName, string $userPass, string $dbType, stri
$I->click('start');
$I->canSeeResponseCodeIs(200);
$I->see('S2 is completely installed!');

// We need '/index.php?' prefix to test urls like /rss.xml
$configFileName = __DIR__ . '/../../config.test.php';
file_put_contents(
$configFileName,
str_replace("define('S2_URL_PREFIX', '');", "define('S2_URL_PREFIX', '/index.php?');", file_get_contents($configFileName))
);
}

public function canWriteComment(bool $premoderation = false): void
Expand Down
16 changes: 9 additions & 7 deletions _tests/acceptance/InstallCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class InstallCest
{
private const URL_PREFIX = '/index.php?';

protected function configProvider(): array
{
return [
Expand Down Expand Up @@ -78,11 +80,11 @@ private function testHierarchyRedirects(AcceptanceTester $I): void
$I->amOnPage('/section1');
$I->seeResponseCodeIs(301);
$I->followRedirect();
$I->seeCurrentUrlEquals('/index.php?/section1/');
$I->seeCurrentUrlEquals(self::URL_PREFIX . '/section1/');
$I->amOnPage('/section1/page1/');
$I->seeResponseCodeIs(301);
$I->followRedirect();
$I->seeCurrentUrlEquals('/index.php?/section1/page1');
$I->seeCurrentUrlEquals(self::URL_PREFIX . '/section1/page1');
$I->startFollowingRedirects();
}

Expand Down Expand Up @@ -359,13 +361,13 @@ private function testBlogExtension(AcceptanceTester $I): void
$I->amOnPage('/blog/tags/blog tag');
$I->seeResponseCodeIs(301);
$I->followRedirect();
$I->seeCurrentUrlEquals('/index.php?/blog/tags/blog%20tag/');
$I->seeCurrentUrlEquals(self::URL_PREFIX . '/blog/tags/blog%20tag/');
$I->seeResponseCodeIsSuccessful();

$I->amOnPage('/blog');
$I->seeResponseCodeIs(301);
$I->followRedirect();
$I->seeCurrentUrlEquals('/index.php?/blog/');
$I->seeCurrentUrlEquals( self::URL_PREFIX . '/blog/');
$I->seeResponseCodeIsSuccessful();
$I->see('New Blog Post Title');
$I->see('New blog post');
Expand Down Expand Up @@ -527,15 +529,15 @@ private function testAdminCommentManagement(AcceptanceTester $I): void
$I->changeSetting('S2_ENABLED_COMMENTS', false);

// Test <!-- s2_last_comments --> and <!-- s2_last_discussions --> placeholders when comments are disabled
$I->amOnPage('/index.php?/');
$I->amOnPage('/');
$I->seeResponseCodeIsSuccessful();

// Check conditional get when the comment form is disabled. Otherwise, there are some random tokens.
// Last comments must be also hidden.
$I->amOnPage('/index.php?/section1/new_page1');
$I->amOnPage('/section1/new_page1');
$headers = $I->grabHeaders();
$I->haveHttpHeader('If-None-Match', $headers['ETag'][0]);
$I->amOnPage('/index.php?/section1/new_page1');
$I->amOnPage('/section1/new_page1');
$I->seeResponseCodeIs(304);
}

Expand Down

0 comments on commit 5273a5e

Please sign in to comment.