mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-18 11:41: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,
|
'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
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
* caching and fallbacks.
|
* caching and fallbacks.
|
||||||
* @note Thanks to MediaWiki for the general logic, although this version
|
* @note Thanks to MediaWiki for the general logic, although this version
|
||||||
* has been entirely rewritten
|
* has been entirely rewritten
|
||||||
|
* @todo Serialized cache for languages
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_LanguageFactory
|
class HTMLPurifier_LanguageFactory
|
||||||
{
|
{
|
||||||
@ -77,41 +78,44 @@ class HTMLPurifier_LanguageFactory
|
|||||||
* Creates a language object, handles class fallbacks
|
* Creates a language object, handles class fallbacks
|
||||||
* @param $config Instance of HTMLPurifier_Config
|
* @param $config Instance of HTMLPurifier_Config
|
||||||
* @param $context Instance of HTMLPurifier_Context
|
* @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
|
// validate language code
|
||||||
$code = $this->validator->validate(
|
if ($code === false) {
|
||||||
$config->get('Core', 'Language'), $config, $context
|
$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
|
if ($code === false) $code = 'en'; // malformed code becomes English
|
||||||
|
|
||||||
$pcode = str_replace('-', '_', $code); // make valid PHP classname
|
$pcode = str_replace('-', '_', $code); // make valid PHP classname
|
||||||
static $depth = 0; // recursion protection
|
static $depth = 0; // recursion protection
|
||||||
|
|
||||||
if ($code == 'en') {
|
if ($code == 'en') {
|
||||||
$class = 'HTMLPurifier_Language';
|
$lang = new HTMLPurifier_Language($config, $context);
|
||||||
$file = $this->dir . '/Language.php';
|
|
||||||
} else {
|
} else {
|
||||||
$class = 'HTMLPurifier_Language_' . $pcode;
|
$class = 'HTMLPurifier_Language_' . $pcode;
|
||||||
$file = $this->dir . '/Language/classes/' . $code . '.php';
|
$file = $this->dir . '/Language/classes/' . $code . '.php';
|
||||||
// PHP5/APC deps bug workaround can go here
|
if (file_exists($file) && class_exists($class)) {
|
||||||
// you can bypass the conditional include by loading the
|
$lang = new $class($config, $context);
|
||||||
// file yourself
|
} else {
|
||||||
if (file_exists($file) && !class_exists($class, false)) {
|
// Go fallback
|
||||||
include_once $file;
|
$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;
|
$lang->code = $code;
|
||||||
|
|
||||||
return $lang;
|
return $lang;
|
||||||
|
@ -234,8 +234,7 @@ 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 = HTMLPurifier_Config::createDefault();
|
$this->config->set('Output', 'TidyFormat', true);
|
||||||
$this->config->set('Core', 'TidyFormat', true);
|
|
||||||
$this->config->set('Output', 'Newline', "\n");
|
$this->config->set('Output', 'Newline', "\n");
|
||||||
|
|
||||||
// nice wrapping please
|
// nice wrapping please
|
||||||
@ -243,9 +242,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 "
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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