diff --git a/get_data.lib.php b/get_data.lib.php
index 4df302f..bbdde5e 100644
--- a/get_data.lib.php
+++ b/get_data.lib.php
@@ -18,6 +18,7 @@ function display_stories($id = NULL) {
$page = '';
$nolink = NULL;
$posted = FALSE;
+ $date = '';
if ($action == 'preview') {
global $file_src;
@@ -65,8 +66,9 @@ searches the title, author, date, and the text of each article.
'."\n";
$entry_id = (int)$entry['id'];
$queue_url = $entry['queue_url'] ? 1 : 0;
$title = h($entry['title']);
+ $entry_date = $date;
if ($entry['date'])
- $date = '';
if ($entry['hidden'])
$page .= '[hidden]';
$page .= 'By ' . h($entry['author']) . '';
- $page .= 'Posted ' . $date . '';
+ $page .= 'Posted ' . $entry_date . '';
$page .= '';
if (isset($file_src)) {
$page .= '
';
diff --git a/tests/php/Unit/DisplayStoriesTest.php b/tests/php/Unit/DisplayStoriesTest.php
index bfe0f7d..c5ed321 100644
--- a/tests/php/Unit/DisplayStoriesTest.php
+++ b/tests/php/Unit/DisplayStoriesTest.php
@@ -46,6 +46,19 @@ class DisplayStoriesTest extends TestCase {
$this->assertStringContainsString('2020-01-02 03:04', $page);
}
+ // A story without a date shows no date, not the date of the story before it
+ public function testAStoryWithoutADateShowsNone(): void {
+ SiteData::install(array('xxx' => array(
+ array('id' => 1, 'title' => 'Dated', 'date' => '2020-01-02 03:04:05'),
+ array('id' => 2, 'title' => 'Undated', 'date' => NULL),
+ )));
+ $GLOBALS['num_stories'] = 5;
+ $page = display_stories();
+ $this->assertSame(1, substr_count($page, 'assertStringContainsString('', $page);
+ $this->assertStringContainsString('', display_stories('2'));
+ }
+
public function testHiddenStoriesAreLeftOutForVisitors(): void {
$this->assertStringNotContainsString('Picture', display_stories());
}