Skip to content

Commit

Permalink
Do not print inline errors in non-HTML output
Browse files Browse the repository at this point in the history
There are several PHP scripts in MantisBT which are used to dynamically
generate non-HTML content, e.g. javascript_*.php, css/common_config.php,
etc. Printing HTML code in these files generates invalid ouput.

This commit allows these special scripts to prevent inline errors
messages from being printed by defining a constant prior to including
core.php (or the Error API), as follows:

define( 'DISABLE_INLINE_ERROR_REPORTING', true );

Fixes #20372
  • Loading branch information
dregad committed Dec 17, 2015
1 parent a3f9d03 commit ab91f9e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions browser_search_plugin.php
Expand Up @@ -27,6 +27,9 @@
* @uses gpc_api.php
*/

# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

require_once( 'core.php' );
require_api( 'config_api.php' );
require_api( 'gpc_api.php' );
Expand Down
4 changes: 3 additions & 1 deletion core/error_api.php
Expand Up @@ -276,7 +276,9 @@ function error_handler( $p_type, $p_error, $p_file, $p_line, array $p_context )
exit(1);

case DISPLAY_ERROR_INLINE:
echo '<div class="error-inline">', $t_error_type, ': ', $t_error_description, '</div>';
if( !defined( 'DISABLE_INLINE_ERROR_REPORTING' ) ) {
echo '<div class="error-inline">', $t_error_type, ': ', $t_error_description, '</div>';
}
$g_error_handled = true;
break;

Expand Down
4 changes: 4 additions & 0 deletions css/common_config.php
Expand Up @@ -26,6 +26,9 @@
* @uses config_api.php
*/

# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

@require_once( dirname( dirname( __FILE__ ) ) . '/core.php' );
require_api( 'lang_api.php' );
require_api( 'config_api.php' );
Expand All @@ -40,6 +43,7 @@
* http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
*/
header( 'X-Content-Type-Options: nosniff' );
$g_display_errors = null;

/**
* WARNING: DO NOT EXPOSE SENSITIVE CONFIGURATION VALUES!
Expand Down
3 changes: 3 additions & 0 deletions css/status_config.php
Expand Up @@ -25,6 +25,9 @@
* @uses config_api.php
*/

# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

@require_once( dirname( dirname( __FILE__ ) ) . '/core.php' );
require_api( 'config_api.php' );

Expand Down
3 changes: 3 additions & 0 deletions csv_export.php
Expand Up @@ -32,6 +32,9 @@
* @uses print_api.php
*/

# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

require_once( 'core.php' );
require_api( 'authentication_api.php' );
require_api( 'columns_api.php' );
Expand Down
3 changes: 3 additions & 0 deletions excel_xml_export.php
Expand Up @@ -36,6 +36,9 @@
* @uses utility_api.php
*/

# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

require_once( 'core.php' );
require_api( 'authentication_api.php' );
require_api( 'bug_api.php' );
Expand Down
3 changes: 3 additions & 0 deletions file_download.php
Expand Up @@ -35,6 +35,9 @@
* @uses utility_api.php
*/

# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

$g_bypass_headers = true; # suppress headers as we will send our own later
define( 'COMPRESSION_DISABLED', true );

Expand Down
3 changes: 3 additions & 0 deletions javascript_config.php
Expand Up @@ -24,6 +24,9 @@
* @uses config_api.php
*/

# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

require_once( 'core.php' );
require_api( 'config_api.php' );

Expand Down
3 changes: 3 additions & 0 deletions javascript_translations.php
Expand Up @@ -25,6 +25,9 @@
* @uses lang_api.php
*/

# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

require_once( 'core.php' );
require_api( 'lang_api.php' );

Expand Down

0 comments on commit ab91f9e

Please sign in to comment.