0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

Add version extraction functionality

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1536 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-02-10 01:33:40 +00:00
parent d00cb1e64d
commit 3d56c1253b
2 changed files with 24 additions and 3 deletions

View File

@ -112,7 +112,16 @@ class ConfigSchema_StringHashReverseAdapter
}
public function extractVersion($description) {
return array($description, false);
$regex = '/This directive (?:has been|was) available since (\d+\.\d+\.\d+)\./';
$regex = str_replace(' ', '\s+', $regex); // allow any number of spaces between statements
$ok = preg_match($regex, $description, $matches);
if ($ok) {
$version = $matches[1];
} else {
$version = false;
}
$description = preg_replace($regex, '', $description, 1);
return array($description, $version);
}
}

View File

@ -8,7 +8,7 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
$schema->addNamespace('Ns', 'Description of ns.');
$schema->addNamespace('Ns2', 'Description of ns2.');
$schema->add('Ns', 'Dir', 'dairy', 'string',
"Description of default.\n");
"Description of default.\nThis directive has been available since 1.2.0.");
$schema->addAllowedValues('Ns', 'Dir', array('dairy', 'meat'));
$schema->addValueAliases('Ns', 'Dir', array('milk' => 'dairy', 'cheese' => 'dairy'));
$schema->addAlias('Ns', 'Dir2', 'Ns', 'Dir');
@ -40,6 +40,7 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
$expect = array(
'ID' => 'Ns.Dir',
'TYPE' => 'string',
'VERSION' => '1.2.0',
'DEFAULT' => "'dairy'",
'DESCRIPTION' => "Description of default.\n",
'ALLOWED' => "'dairy', 'meat'",
@ -84,7 +85,18 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
}
function assertExtraction($desc, $expect_desc, $expect_version) {
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
list($result_desc, $result_version) = $adapter->extractVersion($desc);
$this->assertIdentical($result_desc, $expect_desc);
$this->assertIdentical($result_version, $expect_version);
}
function testExtractSimple() {
$this->assertExtraction("Desc.\nThis directive has been available since 2.0.0.", "Desc.\n", '2.0.0');
}
function testExtractMultiline() {
$this->assertExtraction("Desc.\nThis directive was available\n since 23.4.333.", "Desc.\n", '23.4.333');
}
}