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

折月煮酒 提交于 2019-12-25 04:58:11

问题


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;
}

回答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)




回答2:


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



来源:https://stackoverflow.com/questions/10843600/is-there-a-way-to-stop-htmlpurifier-csstidy-from-forcing-input-css-into-all-lowe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!