is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all lowercase?
Asked Answered
W

2

1

Using PHP/Codeigniter/HTMLPurifier/CSStidy like so:

require_once 'extra/htmlpurifier-4_4_0/library/HTMLPurifier.auto.php';
require_once 'extra/csstidy-1_3/class.csstidy.php';

$input_css = $this->input->post('input_css');

$config = HTMLPurifier_Config::createDefault();
$config->set('Filter.ExtractStyleBlocks', TRUE);

// Create a new purifier instance
$purifier = new HTMLPurifier($config);

// Wrap our CSS in style tags and pass to purifier. 
// we're not actually interested in the html response though
$html = $purifier->purify('<style>'.$input_css.'</style>');

// The "style" blocks are stored seperately
$output_css = $purifier->context->get('StyleBlocks');

// Get the first style block
$unClean_css = $input_css;
$clean_css = $output_css[0];

...is there a way to turn OFF whatever it is inside HTMLPurifier or CSStidy that is causing $clean_css to be forced into lowercase? I need the output to be left alone, in terms of case. I would just not use CSStidy but it is working great for security and compression, etc.. just is also hosing some (e.g. background-image) file paths on account of case-sensitivity. I am not able to fix the issue from the ground up (i.e. I cannot just force all lowercase)... so I ask the question the way I did. A config setting perhaps? (I hope) ...I have been looking but do not see one to do the trick yet.

Update: as nickb points out, there is a config option in CSStidy that might control this, so then the question becomes: How to set that option to FALSE in the context of HTMLpurifier?

Or is that lowercase_s CSSTidy configuration option even the culprit? I don't know because I am so far unable to stop the lowercasing one way or another. I want for example that input like so:

.zzzzzz {
    background:transparent url("images/tmpl_Btn1_CSSdemo.jpg") no-repeat right top;
}

...would NOT become (as it is doing now) :

.zzzzzz {
    background:transparent url("images/tmpl_btn1_cssdemo.jpg") no-repeat right top;
}
Weathercock answered 1/6, 2012 at 2:15 Comment(0)
D
1

Actually, this is an HTML Purifier bug, not a CSS Tidy bug. I'm working on a fix.

Please apply this patch: http://repo.or.cz/w/htmlpurifier.git/commit/f38fca32a9bad0952df221f8664ee2ab13978504 (only the patches to file in library/ are really necessary)

Diapason answered 2/6, 2012 at 15:18 Comment(0)
I
1

You need to set the lowercase_s CSSTidy configuration option to false. Otherwise, it will lowercase all of your selectors for inclusion in XHTML.

Imide answered 1/6, 2012 at 2:29 Comment(8)
Hmm, that's silly of CSS Tidy. Maybe we should change that default.Diapason
where is that? As I look, I keep getting docs showing how to run CSStidy from the command line... I just need an example for setting a CSSTidy configuration option in PHP runtime.Weathercock
I found this: csstidy.sourceforge.net/usage.php , but it does not show how to set the CSStidy config. when in the context of HTMLpurifierWeathercock
I found this source of HTMLPurifier where it is invoking CSSTidy, and I cannot determine if, where, or how it passes any configuration values over to CSSTidy. Maybe @EdwardZ.Yang could shed some light into whether or not it is possible.Imide
@EdwardZ.Yang please do say if you can - how one can set a CSSTidy config option in the context of code like in my OP above. Nick, should I accept your answer now (as it is undoubtedly the best answer, and in the direction I had hoped), or do I wait and accept when I have actually got a definitive solution? ..and so rid of the problem which I posted? Thanks to you both for your time.Weathercock
@Govinda It is your choice - I also found this source which shows that you may be able to just edit the CSSTidy source code (class.csstidy.php) to achieve what you need. I would try changing the values of lowercase_s and case_properties inside the $this->settings array. Although it's not the flexible solution you're looking for, hopefully it'll work.Imide
yes, a runtime config setting would be best, but I'll meanwhile settle for anything. I actually had already found and tried what you just suggested (though I did not think to also play with the case_properties setting; thanks ;-) In any case still no luck; the output is still forced to lowercase no matter what I do with those settings in this file: /path/to/my/doc/root/extra/csstidy-1_3/class.csstidy.php ... so something is overriding .. but where?Weathercock
(If I alter the setting for case_properties in that file, it sticks.. just not so for lowercase_s.)Weathercock
D
1

Actually, this is an HTML Purifier bug, not a CSS Tidy bug. I'm working on a fix.

Please apply this patch: http://repo.or.cz/w/htmlpurifier.git/commit/f38fca32a9bad0952df221f8664ee2ab13978504 (only the patches to file in library/ are really necessary)

Diapason answered 2/6, 2012 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.