diff --git a/NEWS b/NEWS index 39bdadcd..b314dac0 100644 --- a/NEWS +++ b/NEWS @@ -49,6 +49,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier of DOM), HTML Purifier punts to DirectLex - Fatal error with unserialization of ScriptRequired - Created directories are now chmod'ed properly +- Fixed bug with fallback languages in LanguageFactory . Out-of-date documentation revised . UTF-8 encoding check optimization as suggested by Diego . HTMLPurifier_Error removed in favor of exceptions diff --git a/library/HTMLPurifier/Generator.php b/library/HTMLPurifier/Generator.php index 4bb7ff26..e35ce8cf 100644 --- a/library/HTMLPurifier/Generator.php +++ b/library/HTMLPurifier/Generator.php @@ -77,7 +77,7 @@ class HTMLPurifier_Generator 'wrap' => 68, ), 'utf8'); $tidy->cleanRepair(); - $html = ((string) $tidy); // explicit cast necessary + $html = (string) $tidy; // explicit cast necessary } // Normalize newlines to system defined value diff --git a/library/HTMLPurifier/Language.php b/library/HTMLPurifier/Language.php index d42075f3..7337c5bc 100644 --- a/library/HTMLPurifier/Language.php +++ b/library/HTMLPurifier/Language.php @@ -27,6 +27,13 @@ class HTMLPurifier_Language */ public $errorNames = array(); + /** + * True if no message file was found for this language, so English + * is being used instead. Check this if you'd like to notify the + * user that they've used a non-supported language. + */ + public $error = false; + /** * Has the language object been loaded yet? * @todo Make it private, fix usage in HTMLPurifier_LanguageTest diff --git a/library/HTMLPurifier/Language/messages/en-x-testmini.php b/library/HTMLPurifier/Language/messages/en-x-testmini.php new file mode 100644 index 00000000..4b16cd20 --- /dev/null +++ b/library/HTMLPurifier/Language/messages/en-x-testmini.php @@ -0,0 +1,11 @@ + 'HTML Purifier XNone' +); + diff --git a/library/HTMLPurifier/LanguageFactory.php b/library/HTMLPurifier/LanguageFactory.php index e7128224..24ec7544 100644 --- a/library/HTMLPurifier/LanguageFactory.php +++ b/library/HTMLPurifier/LanguageFactory.php @@ -104,14 +104,13 @@ class HTMLPurifier_LanguageFactory $lang = new $class($config, $context); } else { // Go fallback - $fallback = $this->getFallbackFor($code); - // If a language doesn't exist, English's language settings - // file will automatically be used, which DOESN'T have any - // fallback defined. This is fine for settings merging, but - // not so good for figuring out a class to use. - if ($fallback === false) $fallback = 'en'; + $raw_fallback = $this->getFallbackFor($code); + $fallback = $raw_fallback ? $raw_fallback : 'en'; $depth++; $lang = $this->create($config, $context, $fallback); + if (!$raw_fallback) { + $lang->error = true; + } $depth--; } } diff --git a/tests/HTMLPurifier/GeneratorTest.php b/tests/HTMLPurifier/GeneratorTest.php index 99c19a25..e6a0645c 100644 --- a/tests/HTMLPurifier/GeneratorTest.php +++ b/tests/HTMLPurifier/GeneratorTest.php @@ -234,7 +234,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness // abort test if tidy isn't loaded if (!extension_loaded('tidy')) return; - $this->config->set('Output', 'TidyFormat', true); + $this->config = HTMLPurifier_Config::createDefault(); + $this->config->set('Core', 'TidyFormat', true); $this->config->set('Output', 'Newline', "\n"); // nice wrapping please @@ -242,9 +243,9 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness array( new HTMLPurifier_Token_Start('div'), new HTMLPurifier_Token_Text('Text'), - new HTMLPurifier_Token_End('div'), + new HTMLPurifier_Token_End('div') ), - "