diff --git a/core/includes/ajax.inc b/core/includes/ajax.inc index 45bb706..7395b58 100644 --- a/core/includes/ajax.inc +++ b/core/includes/ajax.inc @@ -326,7 +326,7 @@ function ajax_get_form() { // This is likely a hacking attempt as it never happens under normal // circumstances, so we just do nothing. watchdog('ajax', 'Invalid form POST data.', array(), WATCHDOG_WARNING); - drupal_exit(); + return new Response('Forbidden', 403); } // Since some of the submit handlers are run, redirects need to be disabled. diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index eac2f97..b3e2d32 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -617,8 +617,7 @@ function drupal_environment_initialize() { $_SERVER['HTTP_HOST'] = strtolower($_SERVER['HTTP_HOST']); if (!drupal_valid_http_host($_SERVER['HTTP_HOST'])) { // HTTP_HOST is invalid, e.g. if containing slashes it may be an attack. - header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request'); - exit; + return new Response('Bad Request', 400); } } else { @@ -639,9 +638,7 @@ function drupal_environment_initialize() { // Deny execution with enabled "magic quotes" (both GPC and runtime). if (get_magic_quotes_gpc() || get_magic_quotes_runtime()) { - header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); - print "PHP's 'magic_quotes_gpc' and 'magic_quotes_runtime' settings are not supported and must be disabled."; - exit; + return new Response("PHP's 'magic_quotes_gpc' and 'magic_quotes_runtime' settings are not supported and must be disabled.", 500); } // Use session cookies, not transparent sessions that puts the session id in @@ -2302,7 +2299,7 @@ function _drupal_bootstrap_page_cache() { bootstrap_invoke_all('exit'); } // We are done. - exit; + return; } else { header('X-Drupal-Cache: MISS'); diff --git a/core/includes/errors.inc b/core/includes/errors.inc index 92ba6bc..7c9b03d 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -215,7 +215,7 @@ function _drupal_log_error($error, $fatal = FALSE) { // When called from CLI, simply output a plain text message. // Should not translate the string to avoid errors producing more errors. print html_entity_decode(strip_tags(format_string('%type: !message in %function (line %line of %file).', $error))). "\n"; - exit; + return; } } @@ -226,7 +226,7 @@ function _drupal_log_error($error, $fatal = FALSE) { // Should not translate the string to avoid errors producing more errors. print format_string('%type: !message in %function (line %line of %file).', $error); } - exit; + return; } } else { diff --git a/core/modules/system/tests/http.php b/core/modules/system/tests/http.php index 297e3c7..b8400fd 100644 --- a/core/modules/system/tests/http.php +++ b/core/modules/system/tests/http.php @@ -24,18 +24,17 @@ define('DRUPAL_ROOT', getcwd()); require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; -// Make sure this file can only be used by simpletest. -drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); -if (!drupal_valid_test_ua()) { - header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); - exit; -} - // Continue with normal request handling. $request = Request::createFromGlobals(); drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); - $kernel = new DrupalKernel('prod', FALSE); -$response = $kernel->handle($request)->prepare($request)->send(); +// Make sure this file can only be used by simpletest. +if (!drupal_valid_test_ua()) { + $response = new Response('Forbidden', 403); +} +else { + $response = $kernel->handle($request)->prepare($request)->send(); +} $kernel->terminate($request, $response); + diff --git a/core/modules/system/tests/https.php b/core/modules/system/tests/https.php index 8e09a5d..9b7066a 100644 --- a/core/modules/system/tests/https.php +++ b/core/modules/system/tests/https.php @@ -23,18 +23,18 @@ define('DRUPAL_ROOT', getcwd()); require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; -// Make sure this file can only be used by simpletest. -drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); -if (!drupal_valid_test_ua()) { - header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); - exit; -} // Continue with normal request handling. $request = Request::createFromGlobals(); drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); - $kernel = new DrupalKernel('prod', FALSE); -$response = $kernel->handle($request)->prepare($request)->send(); +// Make sure this file can only be used by simpletest. +if (!drupal_valid_test_ua()) { + $response = new Response('Forbidden', 403); +} +else { + $response = $kernel->handle($request)->prepare($request)->send(); +} $kernel->terminate($request, $response); + diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index 03b7cb8..f7ea120 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -6,6 +6,7 @@ */ use Drupal\form_test\Callbacks; +use \Symfony\Component\HttpFoundation\JsonResponse; /** * Implements hook_menu(). @@ -328,10 +329,7 @@ function form_test_permission() { * Form submit handler to return form values as JSON. */ function _form_test_submit_values_json($form, &$form_state) { - // This won't have a proper JSON header, but Drupal doesn't check for that - // anyway so this is fine until it's replaced with a JsonResponse. - print drupal_json_encode($form_state['values']); - drupal_exit(); + return new JsonResponse($form_state['values']); } /** @@ -1056,10 +1054,9 @@ function form_test_form_state_values_clean_form($form, &$form_state) { */ function form_test_form_state_values_clean_form_submit($form, &$form_state) { form_state_values_clean($form_state); - // This won't have a proper JSON header, but Drupal doesn't check for that - // anyway so this is fine until it's replaced with a JsonResponse. - print drupal_json_encode($form_state['values']); - exit; + $response = new JsonResponse($form_state['values']); + $response->send(); + return FALSE; } /** @@ -1086,7 +1083,7 @@ function form_test_form_state_values_clean_advanced_form($form, &$form_state) { function form_test_form_state_values_clean_advanced_form_submit($form, &$form_state) { form_state_values_clean($form_state); print t('You WIN!'); - exit; + return FALSE; } /** diff --git a/core/modules/system/tests/modules/session_test/session_test.module b/core/modules/system/tests/modules/session_test/session_test.module index 3b378ad..294fa9b 100644 --- a/core/modules/system/tests/modules/session_test/session_test.module +++ b/core/modules/system/tests/modules/session_test/session_test.module @@ -157,7 +157,7 @@ function session_test_user_login($edit = array(), $user = NULL) { if ($user->name == 'session_test_user') { // Exit so we can verify that the session was regenerated // before hook_user() was called. - exit; + return new Response('OK', 200); } } diff --git a/core/modules/system/tests/modules/system_test/system_test.module b/core/modules/system/tests/modules/system_test/system_test.module index 4949aec..73edfe0 100644 --- a/core/modules/system/tests/modules/system_test/system_test.module +++ b/core/modules/system/tests/modules/system_test/system_test.module @@ -123,8 +123,7 @@ function system_test_redirect($code) { $code = (int) $code; if ($code != 200) { // Header names are case-insensitive. - header("locaTION: " . url('system-test/redirect/200', array('absolute' => TRUE)), TRUE, $code); - exit; + return new RedirectResponse("locaTION: " . url('system-test/redirect/200', array('absolute' => TRUE)), $code); } return ''; } @@ -147,8 +146,8 @@ function system_test_redirect($code) { function system_test_multiple_redirects($count) { $count = (int) $count; if ($count > 0) { - header("location: " . url('system-test/multiple-redirects/' . --$count, array('absolute' => TRUE)), TRUE, 301); - exit; + // Header names are case-insensitive. + return new RedirectResponse("location: " . url('system-test/multiple-redirects/' . --$count, array('absolute' => TRUE)), 301); } return ''; } @@ -159,18 +158,15 @@ function system_test_set_header() { } function system_test_redirect_noscheme() { - header("Location: localhost/path", TRUE, 301); - exit; + return new RedirectResponse("Location: localhost/path", 301); } function system_test_redirect_noparse() { - header("Location: http:///path", TRUE, 301); - exit; + return new RedirectResponse("Location: http:///path", 301); } function system_test_redirect_invalid_scheme() { - header("Location: ftp://localhost/path", TRUE, 301); - exit; + return new RedirectResponse("Location: ftp://localhost/path", 301); } /** diff --git a/core/modules/system/tests/modules/url_alter_test/url_alter_test.module b/core/modules/system/tests/modules/url_alter_test/url_alter_test.module index a5ca13d..4637454 100644 --- a/core/modules/system/tests/modules/url_alter_test/url_alter_test.module +++ b/core/modules/system/tests/modules/url_alter_test/url_alter_test.module @@ -22,8 +22,7 @@ function url_alter_test_menu() { * Menu callback. */ function url_alter_test_foo() { - print 'current_path=' . current_path() . ' request_path=' . request_path(); - exit; + return new Response('current_path=' . current_path() . ' request_path=' . request_path(), 200); } /** diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 042263c..0baa1c9 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -122,8 +122,9 @@ function taxonomy_autocomplete($field_name, $tags_typed = '') { if (!($field = field_info_field($field_name)) || $field['type'] !== 'taxonomy_term_reference') { // Error string. The JavaScript handler will realize this is not JSON and // will display it as debugging information. - print t('Taxonomy field @field_name not found.', array('@field_name' => $field_name)); - exit; + $response = new JsonResponse(); + $response->setContent(t('Taxonomy field @field_name not found.', array('@field_name' => $field_name))); + return $response; } // The user enters a comma-separated list of tags. We only autocomplete the last tag. diff --git a/core/update.php b/core/update.php index 968e8f4..d5b81ff 100644 --- a/core/update.php +++ b/core/update.php @@ -32,7 +32,7 @@ // load that file yet as it would cause a fatal error on older versions of PHP. if (version_compare(PHP_VERSION, '5.3.3') < 0) { print 'Your PHP installation is too old. Drupal requires at least PHP 5.3.3. See the system requirements page for more information.'; - exit; + return; } /**