Menu

#148 HtmlReporter defaults to wrong character-set

open
nobody
5
2008-06-19
2008-06-19
Anonymous
No

Using autorun, there's no opportunity to specify the character-set HtmlReporter uses - so it goes to the default of 'ISO-8859-1'.

This can lead to bogus/misleading output when an assertEqual fails with two multi-byte strings.

As it's possible to use php.ini (or .htaccess) to set character encodings, it would be better to check which encoding is in use, rather than arbitrarily default to a legacy single-byte character set.

Though I've been unable to find 'get_current_charset' amongst PHP's 3,000 built-in functions, the following code seems to work:

(apologies for the formatting)

function HtmlReporter($character_set = null) {
$this->SimpleReporter();
debug(true, 'mb_http_output: %s', mb_http_output());
if (isset($character_set))
$this->_character_set = $character_set;
else if (ini_get('default_charset'))
$this->_character_set = ini_get('default_charset');
else if (function_exists('mb_internal_encoding'))
$this->_character_set = mb_internal_encoding();
else
$this->_character_set = 'ISO-8859-1';
}

Discussion

  • Edward Z. Yang

    Edward Z. Yang - 2008-12-06

    This sounds like a sensible addition.

     
  • Edward Z. Yang

    Edward Z. Yang - 2008-12-06

    Some implementation comments:

    - This addition would be mostly useless (but probably not harmful) for people who are configuring the encodings at runtime, as opposed to in a php.ini file. The way one would have detected at runtime would be with the function headers_list()

    - It is a good thing that the encoding parameter does not affect the actual running of tests. Ideally, you should be explicitly stating your encoding so that running your tests on another box won't suddenly result in garbled output

     

Log in to post a comment.

MongoDB Logo MongoDB