mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 06:07:26 +02:00
[3.1.0] Fix bug with 3.1.0-dev version number (the dash caused problems, so we switched to commas)
- Refactored out null definition cache during HTMLDefinition tests git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1697 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -11,7 +11,7 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
|
||||
$config->setReturnValue('get', 2, array('Test', 'DefinitionRev'));
|
||||
$config->version = '1.0.0';
|
||||
|
||||
$config_md5 = '1.0.0-serial-2';
|
||||
$config_md5 = '1.0.0,serial,2';
|
||||
|
||||
$file = realpath(
|
||||
$rel_file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer/Test/' .
|
||||
@@ -186,9 +186,9 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
|
||||
|
||||
$def_original = $this->generateDefinition();
|
||||
$cache->add($def_original, $config);
|
||||
$this->assertFileExist($dir . '/Test/1.0.0-serial-1.ser');
|
||||
$this->assertFileExist($dir . '/Test/1.0.0,serial,1.ser');
|
||||
|
||||
unlink($dir . '/Test/1.0.0-serial-1.ser');
|
||||
unlink($dir . '/Test/1.0.0,serial,1.ser');
|
||||
rmdir( $dir . '/Test');
|
||||
|
||||
}
|
||||
|
@@ -13,16 +13,17 @@ class HTMLPurifier_DefinitionCacheTest extends HTMLPurifier_Harness
|
||||
$config->setReturnValue('get', 10, array('Test', 'DefinitionRev'));
|
||||
$config->setReturnValue('getBatchSerial', 'hash', array('Test'));
|
||||
|
||||
$this->assertIdentical($cache->isOld('1.0.0-hash-10', $config), false);
|
||||
$this->assertIdentical($cache->isOld('1.5.0-hash-1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0,hash,10', $config), false);
|
||||
$this->assertIdentical($cache->isOld('1.5.0,hash,1', $config), true);
|
||||
|
||||
$this->assertIdentical($cache->isOld('0.9.0-hash-1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0-hash-1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0beta-hash-11', $config), true);
|
||||
$this->assertIdentical($cache->isOld('0.9.0,hash,1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0,hash,1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0beta,hash,11', $config), true);
|
||||
|
||||
$this->assertIdentical($cache->isOld('0.9.0-hash2-1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0-hash2-1', $config), false); // if hash is different, don't touch!
|
||||
$this->assertIdentical($cache->isOld('1.0.0beta-hash2-11', $config), true);
|
||||
$this->assertIdentical($cache->isOld('0.9.0,hash2,1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0,hash2,1', $config), false); // if hash is different, don't touch!
|
||||
$this->assertIdentical($cache->isOld('1.0.0beta,hash2,11', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0-dev,hash2,11', $config), true);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,13 @@
|
||||
class HTMLPurifier_HTMLDefinitionTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
function expectError($error = false, $message = '%s') {
|
||||
// Because we're testing a definition, it's vital that the cache
|
||||
// is turned off for tests that expect errors.
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
parent::expectError($error);
|
||||
}
|
||||
|
||||
function test_parseTinyMCEAllowedList() {
|
||||
|
||||
$def = new HTMLPurifier_HTMLDefinition();
|
||||
@@ -85,21 +92,18 @@ a[href|title]
|
||||
}
|
||||
|
||||
function test_AllowedElements_invalidElement() {
|
||||
$this->config->set('Cache', 'DefinitionImpl', null); // Necessary to ensure error is thrown
|
||||
$this->config->set('HTML', 'AllowedElements', 'obviously_invalid,p');
|
||||
$this->expectError(new PatternExpectation("/Element 'obviously_invalid' is not supported/"));
|
||||
$this->assertPurification_AllowedElements_p();
|
||||
}
|
||||
|
||||
function test_AllowedElements_invalidElement_xssAttempt() {
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
$this->config->set('HTML', 'AllowedElements', '<script>,p');
|
||||
$this->expectError(new PatternExpectation("/Element '<script>' is not supported/"));
|
||||
$this->assertPurification_AllowedElements_p();
|
||||
}
|
||||
|
||||
function test_AllowedElements_multipleInvalidElements() {
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
$this->config->set('HTML', 'AllowedElements', 'dr-wiggles,dr-pepper,p');
|
||||
$this->expectError(new PatternExpectation("/Element 'dr-wiggles' is not supported/"));
|
||||
$this->expectError(new PatternExpectation("/Element 'dr-pepper' is not supported/"));
|
||||
@@ -153,21 +157,18 @@ a[href|title]
|
||||
}
|
||||
|
||||
function test_AllowedAttributes_local_invalidAttribute() {
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
$this->config->set('HTML', 'AllowedAttributes', array('p@style', 'p@<foo>'));
|
||||
$this->expectError(new PatternExpectation("/Attribute '<foo>' in element 'p' not supported/"));
|
||||
$this->assertPurification_AllowedAttributes_local_p_style();
|
||||
}
|
||||
|
||||
function test_AllowedAttributes_global_invalidAttribute() {
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
$this->config->set('HTML', 'AllowedAttributes', array('style', '<foo>'));
|
||||
$this->expectError(new PatternExpectation("/Global attribute '<foo>' is not supported in any elements/"));
|
||||
$this->assertPurification_AllowedAttributes_global_style();
|
||||
}
|
||||
|
||||
function test_AllowedAttributes_local_invalidAttributeDueToMissingElement() {
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
$this->config->set('HTML', 'AllowedAttributes', 'p.style,foo.style');
|
||||
$this->expectError(new PatternExpectation("/Cannot allow attribute 'style' if element 'foo' is not allowed\/supported/"));
|
||||
$this->assertPurification_AllowedAttributes_local_p_style();
|
||||
@@ -208,7 +209,6 @@ a[href|title]
|
||||
}
|
||||
|
||||
function test_ForbiddenAttributes_incorrectSyntax() {
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
$this->config->set('HTML', 'ForbiddenAttributes', 'b.style');
|
||||
$this->expectError("Error with b.style: tag.attr syntax not supported for HTML.ForbiddenAttributes; use tag@attr instead");
|
||||
$this->assertPurification('<b style="float:left;">Test</b>');
|
||||
|
Reference in New Issue
Block a user