mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 08:21:52 +00:00
[3.1.0] Fix buggy LanguageFactory. This revision is incomplete.
- Some bogus commits to Generator were made, and will be reverted next revision. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1722 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
cb5d5d0648
commit
00ea2062d4
@ -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
|
||||
|
@ -5,6 +5,7 @@
|
||||
* caching and fallbacks.
|
||||
* @note Thanks to MediaWiki for the general logic, although this version
|
||||
* has been entirely rewritten
|
||||
* @todo Serialized cache for languages
|
||||
*/
|
||||
class HTMLPurifier_LanguageFactory
|
||||
{
|
||||
@ -77,41 +78,44 @@ class HTMLPurifier_LanguageFactory
|
||||
* Creates a language object, handles class fallbacks
|
||||
* @param $config Instance of HTMLPurifier_Config
|
||||
* @param $context Instance of HTMLPurifier_Context
|
||||
* @param $code Code to override configuration with. Private parameter.
|
||||
*/
|
||||
public function create($config, $context) {
|
||||
public function create($config, $context, $code = false) {
|
||||
|
||||
// validate language code
|
||||
$code = $this->validator->validate(
|
||||
$config->get('Core', 'Language'), $config, $context
|
||||
);
|
||||
if ($code === false) {
|
||||
$code = $this->validator->validate(
|
||||
$config->get('Core', 'Language'), $config, $context
|
||||
);
|
||||
} else {
|
||||
$code = $this->validator->validate($code, $config, $context);
|
||||
}
|
||||
if ($code === false) $code = 'en'; // malformed code becomes English
|
||||
|
||||
$pcode = str_replace('-', '_', $code); // make valid PHP classname
|
||||
static $depth = 0; // recursion protection
|
||||
|
||||
if ($code == 'en') {
|
||||
$class = 'HTMLPurifier_Language';
|
||||
$file = $this->dir . '/Language.php';
|
||||
$lang = new HTMLPurifier_Language($config, $context);
|
||||
} else {
|
||||
$class = 'HTMLPurifier_Language_' . $pcode;
|
||||
$file = $this->dir . '/Language/classes/' . $code . '.php';
|
||||
// PHP5/APC deps bug workaround can go here
|
||||
// you can bypass the conditional include by loading the
|
||||
// file yourself
|
||||
if (file_exists($file) && !class_exists($class, false)) {
|
||||
include_once $file;
|
||||
if (file_exists($file) && class_exists($class)) {
|
||||
$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';
|
||||
$depth++;
|
||||
$lang = $this->create($config, $context, $fallback);
|
||||
$depth--;
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists($class, false)) {
|
||||
// go fallback
|
||||
$fallback = HTMLPurifier_LanguageFactory::getFallbackFor($code);
|
||||
$depth++;
|
||||
$lang = HTMLPurifier_LanguageFactory::factory( $fallback );
|
||||
$depth--;
|
||||
} else {
|
||||
$lang = new $class($config, $context);
|
||||
}
|
||||
$lang->code = $code;
|
||||
|
||||
return $lang;
|
||||
|
@ -234,8 +234,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
// abort test if tidy isn't loaded
|
||||
if (!extension_loaded('tidy')) return;
|
||||
|
||||
$this->config = HTMLPurifier_Config::createDefault();
|
||||
$this->config->set('Core', 'TidyFormat', true);
|
||||
$this->config->set('Output', 'TidyFormat', true);
|
||||
$this->config->set('Output', 'Newline', "\n");
|
||||
|
||||
// nice wrapping please
|
||||
@ -243,9 +242,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'),
|
||||
),
|
||||
"<div>\n Text\n</div>\n"
|
||||
"<div>\n Text\n</div>\n "
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -45,5 +45,11 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
|
||||
|
||||
}
|
||||
|
||||
function testFullFallback() {
|
||||
$factory = HTMLPurifier_LanguageFactory::instance();
|
||||
$this->config->set('Core', 'Language', 'en-x-none');
|
||||
$language = $factory->create($this->config, $this->context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user