diff --git a/security/Security.php b/security/Security.php index 840af3f9d..c6c6cd402 100644 --- a/security/Security.php +++ b/security/Security.php @@ -336,7 +336,9 @@ class Security extends Controller implements TemplateGlobalProvider { $this->getResponse()->addHeader('X-Frame-Options', $this->config()->frame_options); // Prevent search engines from indexing the login page - $this->getResponse()->addHeader('X-Robots-Tag', $this->config()->robots_tag); + if ($this->config()->robots_tag) { + $this->getResponse()->addHeader('X-Robots-Tag', $this->config()->robots_tag); + } } public function index() { diff --git a/tests/security/SecurityTest.php b/tests/security/SecurityTest.php index bd2c8ed0f..a2206e37d 100644 --- a/tests/security/SecurityTest.php +++ b/tests/security/SecurityTest.php @@ -581,6 +581,13 @@ class SecurityTest extends FunctionalTest { $this->assertContains('noindex', $robotsHeader); } + public function testDoNotSendEmptyRobotsHeaderIfNotDefined() { + Config::inst()->update('Security', 'robots_tag', null); + $response = $this->get(Config::inst()->get('Security', 'login_url')); + $robotsHeader = $response->getHeader('X-Robots-Tag'); + $this->assertNull($robotsHeader); + } + /** * Execute a log-in form using Director::test(). * Helper method for the tests above