Be careful: Magento layer filter label is not html escaped

我发现 Magento 1.4.1.1 app/design/frontend/base/default/template/catalog/layer/filter.phtml 是这么写的:

<ol>
<?php foreach ($this->getItems() as $_item): ?>
<li>
<?php if ($_item->getCount() > 0): ?>
<a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
<?php else: echo $_item->getLabel() ?>
<?php endif; ?>
(<?php echo $_item->getCount() ?>)
</li>
<?php endforeach ?>
</ol>

我觉得不太好,因为 staff 在设置 filter label 通常会忽视 html escape,所以最好是

$this->htmlEscape($_item->getLabel());

但这样一来把 price filter 正常的 html 输出给搞乱了。要兼顾普通 filter 和 price filter,我还没有一个比较 neat 的方案,只好要求 staff 做好 filter label 的 html escape。

同样的问题在 app/design/frontend/base/default/template/catalog/layer/state.phtml 中也存在。

Leave a comment

Your email address will not be published. Required fields are marked *