mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 23:28:42 +00:00
[3.1.0] Fixed bug with fallback languages in LanguageFactory
- Also, reverted bogus Generator changes git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1723 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
00ea2062d4
commit
86b1da9b6f
1
NEWS
1
NEWS
@ -49,6 +49,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
of DOM), HTML Purifier punts to DirectLex
|
of DOM), HTML Purifier punts to DirectLex
|
||||||
- Fatal error with unserialization of ScriptRequired
|
- Fatal error with unserialization of ScriptRequired
|
||||||
- Created directories are now chmod'ed properly
|
- Created directories are now chmod'ed properly
|
||||||
|
- Fixed bug with fallback languages in LanguageFactory
|
||||||
. Out-of-date documentation revised
|
. Out-of-date documentation revised
|
||||||
. UTF-8 encoding check optimization as suggested by Diego
|
. UTF-8 encoding check optimization as suggested by Diego
|
||||||
. HTMLPurifier_Error removed in favor of exceptions
|
. HTMLPurifier_Error removed in favor of exceptions
|
||||||
|
@ -77,7 +77,7 @@ class HTMLPurifier_Generator
|
|||||||
'wrap' => 68,
|
'wrap' => 68,
|
||||||
), 'utf8');
|
), 'utf8');
|
||||||
$tidy->cleanRepair();
|
$tidy->cleanRepair();
|
||||||
$html = ((string) $tidy); // explicit cast necessary
|
$html = (string) $tidy; // explicit cast necessary
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize newlines to system defined value
|
// Normalize newlines to system defined value
|
||||||
|
@ -27,6 +27,13 @@ class HTMLPurifier_Language
|
|||||||
*/
|
*/
|
||||||
public $errorNames = array();
|
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?
|
* Has the language object been loaded yet?
|
||||||
* @todo Make it private, fix usage in HTMLPurifier_LanguageTest
|
* @todo Make it private, fix usage in HTMLPurifier_LanguageTest
|
||||||
|
11
library/HTMLPurifier/Language/messages/en-x-testmini.php
Normal file
11
library/HTMLPurifier/Language/messages/en-x-testmini.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// private language message file for unit testing purposes
|
||||||
|
// this language file has no class associated with it
|
||||||
|
|
||||||
|
$fallback = 'en';
|
||||||
|
|
||||||
|
$messages = array(
|
||||||
|
'HTMLPurifier' => 'HTML Purifier XNone'
|
||||||
|
);
|
||||||
|
|
@ -104,14 +104,13 @@ class HTMLPurifier_LanguageFactory
|
|||||||
$lang = new $class($config, $context);
|
$lang = new $class($config, $context);
|
||||||
} else {
|
} else {
|
||||||
// Go fallback
|
// Go fallback
|
||||||
$fallback = $this->getFallbackFor($code);
|
$raw_fallback = $this->getFallbackFor($code);
|
||||||
// If a language doesn't exist, English's language settings
|
$fallback = $raw_fallback ? $raw_fallback : 'en';
|
||||||
// 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';
|
|
||||||
$depth++;
|
$depth++;
|
||||||
$lang = $this->create($config, $context, $fallback);
|
$lang = $this->create($config, $context, $fallback);
|
||||||
|
if (!$raw_fallback) {
|
||||||
|
$lang->error = true;
|
||||||
|
}
|
||||||
$depth--;
|
$depth--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
|||||||
// abort test if tidy isn't loaded
|
// abort test if tidy isn't loaded
|
||||||
if (!extension_loaded('tidy')) return;
|
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");
|
$this->config->set('Output', 'Newline', "\n");
|
||||||
|
|
||||||
// nice wrapping please
|
// nice wrapping please
|
||||||
@ -242,9 +243,9 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
|||||||
array(
|
array(
|
||||||
new HTMLPurifier_Token_Start('div'),
|
new HTMLPurifier_Token_Start('div'),
|
||||||
new HTMLPurifier_Token_Text('Text'),
|
new HTMLPurifier_Token_Text('Text'),
|
||||||
new HTMLPurifier_Token_End('div'),
|
new HTMLPurifier_Token_End('div')
|
||||||
),
|
),
|
||||||
"<div>\n Text\n</div>\n "
|
"<div>\n Text\n</div>\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,20 @@
|
|||||||
class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
|
class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protected reference of global factory we're testing.
|
||||||
|
*/
|
||||||
|
protected $factory;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
$this->factory = HTMLPurifier_LanguageFactory::instance();
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
|
|
||||||
$factory = HTMLPurifier_LanguageFactory::instance();
|
$this->config->set('Core', 'Language', 'en');
|
||||||
|
$language = $this->factory->create($this->config, $this->context);
|
||||||
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en'));
|
|
||||||
$context = new HTMLPurifier_Context();
|
|
||||||
$language = $factory->create($config, $context);
|
|
||||||
|
|
||||||
$this->assertIsA($language, 'HTMLPurifier_Language');
|
$this->assertIsA($language, 'HTMLPurifier_Language');
|
||||||
$this->assertIdentical($language->code, 'en');
|
$this->assertIdentical($language->code, 'en');
|
||||||
@ -19,18 +26,12 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
|
|||||||
$language->load();
|
$language->load();
|
||||||
$this->assertNotEqual(count($language->messages), 0);
|
$this->assertNotEqual(count($language->messages), 0);
|
||||||
|
|
||||||
// actual tests for content can be found in LanguageTest
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testFallback() {
|
function testFallback() {
|
||||||
|
|
||||||
$factory = HTMLPurifier_LanguageFactory::instance();
|
$this->config->set('Core', 'Language', 'en-x-test');
|
||||||
|
$language = $this->factory->create($this->config, $this->context);
|
||||||
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en-x-test'));
|
|
||||||
$context = new HTMLPurifier_Context();
|
|
||||||
|
|
||||||
$language = $factory->create($config, $context);
|
|
||||||
|
|
||||||
$this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
|
$this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
|
||||||
$this->assertIdentical($language->code, 'en-x-test');
|
$this->assertIdentical($language->code, 'en-x-test');
|
||||||
@ -45,10 +46,23 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testFullFallback() {
|
function testFallbackWithNoClass() {
|
||||||
$factory = HTMLPurifier_LanguageFactory::instance();
|
$this->config->set('Core', 'Language', 'en-x-testmini');
|
||||||
$this->config->set('Core', 'Language', 'en-x-none');
|
$language = $this->factory->create($this->config, $this->context);
|
||||||
$language = $factory->create($this->config, $this->context);
|
$this->assertIsA($language, 'HTMLPurifier_Language');
|
||||||
|
$this->assertIdentical($language->code, 'en-x-testmini');
|
||||||
|
$language->load();
|
||||||
|
$this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier XNone');
|
||||||
|
$this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza');
|
||||||
|
$this->assertIdentical($language->error, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNoSuchLanguage() {
|
||||||
|
$this->config->set('Core', 'Language', 'en-x-testnone');
|
||||||
|
$language = $this->factory->create($this->config, $this->context);
|
||||||
|
$this->assertIsA($language, 'HTMLPurifier_Language');
|
||||||
|
$this->assertIdentical($language->code, 'en-x-testnone');
|
||||||
|
$this->assertIdentical($language->error, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user