silverstripe-cms icon indicating copy to clipboard operation
silverstripe-cms copied to clipboard

Redirector page leaking draft content

Open mfendeksilverstripe opened this issue 4 years ago • 0 comments

Redirector page leaking draft content

Test setup

Page A - published, has HTML field with a page link which points to Redirector page Redirector page - unpublished, redirects to Page B Page B - published

Expected result

When rendering Page A in Live stage, the link inside HTML field is empty.

Actual result

When rendering Page A in Live stage, the link inside HTML field links to Page B.

Notes

Tested on SS 4.5 The publish state of Redirector page doesn't matter. This is related to the shortcode parsing code:

public static function link_shortcode_handler($arguments, $content = null, $parser = null)
{
    if (!isset($arguments['id']) || !is_numeric($arguments['id'])) {
        return null;
    }

    /** @var SiteTree $page */
    if (!($page = DataObject::get_by_id(self::class, $arguments['id']))         // Get the current page by ID.
        && !($page = Versioned::get_latest_version(self::class, $arguments['id'])) // Attempt link to old version.
    ) {
        return null; // There were no suitable matches at all.
    }

    /** @var SiteTree $page */
    $link = Convert::raw2att($page->Link());

    if ($content) {
        return sprintf('<a href="%s">%s</a>', $link, $parser->parse($content));
    } else {
        return $link;
    }
}

Versioned::get_latest_version will fetch even unpublished page. Normally, this isn't an issue but for Redirector pages, I would argue that this behaviour is unexpected.

My recommendation is to either:

  • keep and document current behaviour
  • add an exception to redirector pages

mfendeksilverstripe avatar Apr 15 '20 02:04 mfendeksilverstripe