Welcome! » Log In » Create A New Profile

DefinitionCache/Serializer write access required?

Posted by mfb 
mfb
DefinitionCache/Serializer write access required?
May 23, 2008 09:14PM

Is it just me or is write access to the DefinitionCache/Serializer directory still required, even if you specify some other cache directory in the config? My application uses one cache directory for all cache files; this is one of the few directories the app has write access to and I'd like htmlpurifier to play along. However I'm still getting errors if htmlpurifier cannot write to the default cache path.

Re: DefinitionCache/Serializer write access required?
May 23, 2008 10:01PM

It shouldn't. What line are the errors being emitted from?

mfb
Re: DefinitionCache/Serializer write access required?
May 23, 2008 11:26PM

Here's a stack trace:

[error] PHP Fatal error:  Directory /classes/htmlpurifier/standalone/HTMLPurifier/DefinitionCache/Serializer not writable, please alter file permissions in /classes/htmlpurifier/HTMLPurifier.standalone.php on line 9684
[error] PHP Stack trace:
[error] PHP   1. {main}() /website/publish.php:0
[error] PHP   2. Page->build_page() /website/publish.php:18
[error] PHP   3. publish->execute() /classes/page_class.inc:120
[error] PHP   4. publish->clean_posted_data() /classes/pages/article/publish.inc:21
[error] PHP   5. Renderer->html_purify() /classes/pages/article/publish.inc:493
[error] PHP   6. HTMLPurifier->purify() /classes/renderer/renderer_class.inc:580
[error] PHP   7. HTMLPurifier_Strategy_Composite->execute() /classes/htmlpurifier/HTMLPurifier.standalone.php:200
[error] PHP   8. HTMLPurifier_Strategy_RemoveForeignElements->execute() /classes/htmlpurifier/HTMLPurifier.standalone.php:11975
[error] PHP   9. HTMLPurifier_Generator->__construct() /classes/htmlpurifier/HTMLPurifier.standalone.php:12643
[error] PHP  10. HTMLPurifier_Config->getHTMLDefinition() /classes/htmlpurifier/HTMLPurifier.standalone.php:3415
[error] PHP  11. HTMLPurifier_Config->getDefinition() /classes/htmlpurifier/HTMLPurifier.standalone.php:1470
[error] PHP  12. HTMLPurifier_DefinitionCache_Decorator_Cleanup->get() /classes/htmlpurifier/HTMLPurifier.standalone.php:1501
[error] PHP  13. HTMLPurifier_DefinitionCache_Decorator->cleanup() /classes/htmlpurifier/HTMLPurifier.standalone.php:9728
[error] PHP  14. HTMLPurifier_DefinitionCache_Serializer->cleanup() /classes/htmlpurifier/HTMLPurifier.standalone.php:9475
[error] PHP  15. HTMLPurifier_DefinitionCache_Serializer->_prepareDir() /classes/htmlpurifier/HTMLPurifier.standalone.php:9573
[error] PHP  16. HTMLPurifier_DefinitionCache_Serializer->_testPermissions() /classes/htmlpurifier/HTMLPurifier.standalone.php:9638
[error] PHP  17. trigger_error() /classes/htmlpurifier/HTMLPurifier.standalone.php:9684
Re: DefinitionCache/Serializer write access required?
May 24, 2008 12:02AM

I did a quick sanity check on the code, and everything seemed to work ok. What is the configuration? You've set %Cache.SerializerPath appropriately, correct?

This issue is caused by creating new instances of HTMLPurifier_Generator without passing $config to the constructor. Please find a patch below.

diff -urN htmlpurifier-3.1.0.orig/library/HTMLPurifier/ChildDef/Required.php htmlpurifier-3.1.0/library/HTMLPurifier/ChildDef/Required.php
--- htmlpurifier-3.1.0.orig/library/HTMLPurifier/ChildDef/Required.php  2008-01-27 02:54:41.000000000 +0100
+++ htmlpurifier-3.1.0/library/HTMLPurifier/ChildDef/Required.php       2008-05-25 17:32:41.000000000 +0200
@@ -57,7 +57,7 @@
         // generator
         static $gen = null;
         if ($gen === null) {
-            $gen = new HTMLPurifier_Generator();
+            $gen = new HTMLPurifier_Generator($config, $context);
         }

         foreach ($tokens_of_children as $token) {
diff -urN htmlpurifier-3.1.0.orig/library/HTMLPurifier/Strategy/MakeWellFormed.php htmlpurifier-3.1.0/library/HTMLPurifier/Strategy/MakeWellFormed.php
--- htmlpurifier-3.1.0.orig/library/HTMLPurifier/Strategy/MakeWellFormed.php    2008-02-10 21:34:39.000000000 +0100
+++ htmlpurifier-3.1.0/library/HTMLPurifier/Strategy/MakeWellFormed.php 2008-05-25 17:31:38.000000000 +0200
@@ -18,7 +18,7 @@

         // local variables
         $result = array();
-        $generator = new HTMLPurifier_Generator();
+        $generator = new HTMLPurifier_Generator($config, $context);
         $escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
         $e = $context->get('ErrorCollector', true);

diff -urN htmlpurifier-3.1.0.orig/library/HTMLPurifier/Strategy/RemoveForeignElements.php htmlpurifier-3.1.0/library/HTMLPurifier/Strategy/RemoveForeignElements.php
--- htmlpurifier-3.1.0.orig/library/HTMLPurifier/Strategy/RemoveForeignElements.php     2008-02-10 21:34:39.000000000 +0100
+++ htmlpurifier-3.1.0/library/HTMLPurifier/Strategy/RemoveForeignElements.php  2008-05-25 17:31:50.000000000 +0200
@@ -13,7 +13,7 @@

     public function execute($tokens, $config, $context) {
         $definition = $config->getHTMLDefinition();
-        $generator = new HTMLPurifier_Generator();
+        $generator = new HTMLPurifier_Generator($config, $context);
         $result = array();

         $escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
Re: DefinitionCache/Serializer write access required?
May 25, 2008 11:35PM

vs, thank you for the patch. With a few minor modifications, things are working great. How would you like to be credited in the changelog?

mfb
Re: DefinitionCache/Serializer write access required?
May 26, 2008 05:33AM

Thanks all, I installed the nightly build and it seemed to fix the issue.

Sorry, you do not have permission to post/reply in this forum.