Warning: vsprintf() Too Few Arguments in Mage/Adminhtml/Helper/Sales.php

ce-1.9.1.0historysales-order

I am testing CE ver 1.9.1.1 and discover the error. To replicate, go to any sales order page in admin and enter "80%" in the comment history, click the button Submit Comment. So far so good, then hit F5 to refresh the page and you'll see the error:

Warning: vsprintf(): Too few arguments in …/app/code/core/Mage/Adminhtml/Helper/Sales.php on line 133

Here's the function that contains line 133:

public function escapeHtmlWithLinks($data, $allowedTags = null)
{
    if (is_string($data) && is_array($allowedTags) && in_array('a', $allowedTags)) {
        $links = array();
        $i = 1;
        $regexp = '@(<a[^>]*>(?:[^<]|<[^/]|</[^a]|</a[^>])*</a>)@';
        while (preg_match($regexp, $data, $matches)) {
            $links[] = $matches[1];
            $data = str_replace($matches[1], '%' . $i . '$s', $data);
            ++$i;
        }
        $data = Mage::helper('core')->escapeHtml($data, $allowedTags);
        return vsprintf($data, $links);
    }
    return Mage::helper('core')->escapeHtml($data, $allowedTags);
}

Is this a bug? Is there a workaround?

Best Answer

Percent sign used for conversion specification in vsprintf. So, you just need to escape it.

update

if (is_string($data) && is_array($allowedTags) && in_array('a', $allowedTags)) {

to

if (is_string($data) && is_array($allowedTags) && in_array('a', $allowedTags)) {
        $data = str_replace('%', '%%', $data);
Related Topic