Zend 2 Form View Helper语言不连贯

时间:2014-04-12 11:34:11

标签: php zend-framework2 escaping

Zend Framework 2引入了Escaper,它有许多方法可以作为上下文进行转义。

我不明白一件事。为什么Zend \ Form \ View \ Helper \ AbstractHelper.php使用escapeHtml()而不是escapeHtmlAttr()作为html属性上下文。

public function createAttributesString(array $attributes)
{
    $attributes = $this->prepareAttributes($attributes);
    $escape     = $this->getEscapeHtmlHelper();
    $strings    = array();
    foreach ($attributes as $key => $value) {
        $key = strtolower($key);
        if (!$value && isset($this->booleanAttributes[$key])) {
            // Skip boolean attributes that expect empty string as false value
            if ('' === $this->booleanAttributes[$key]['off']) {
                continue;
            }
        }

        //check if attribute is translatable
        if (isset($this->translatableAttributes[$key]) && !empty($value)) {
            if (($translator = $this->getTranslator()) !== null) {
                $value = $translator->translate(
                        $value, $this->getTranslatorTextDomain()
                );
            }
        }

        //@TODO Escape event attributes like AbstractHtmlElement view helper does in htmlAttribs ??
        $strings[] = sprintf('%s="%s"', $escape($key), $escape($value));
    }
    return implode(' ', $strings);
}

我不是XSS的专家,所以请向我澄清一下。我想将Zend_View(ZF1)与Zend \ Escaper集成到我维护的项目中。

1 个答案:

答案 0 :(得分:1)

答案是:它应该使用escapeHtmlAttr(),我们最近修补了它:http://framework.zend.com/security/advisory/ZF2014-03