Development

#2653 (sfFillInForm with AJAX does not handle charset correctly)

You must first sign up to be able to contribute.

Ticket #2653 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

sfFillInForm with AJAX does not handle charset correctly

Reported by: robert Assigned to: FabianLange
Priority: major Milestone: 1.0.14
Component: validation Version: 1.0.9
Keywords: sffillinform fillin form ajax utf-8 charset encoding Cc:
Qualification: Unreviewed

Description

The sfFillInForm uses a DomDocument? and loadHTML to load its contents. But the loadHTML method assumes ISO-8859-1 encoding when there is no encoding given in the head section. Because AJAX responses do not have a head section in the response, the sfFillInForm does not handle UTF-8 responses correctly.

see: http://at.php.net/manual/en/function.dom-domdocument-loadhtml.php#78243

fix for the loadHTML method (more a quickhack than a fix....):

  public function fillInHtml($html, $formName, $formId, $values)
  {
	$dom = new DomDocument('1.0', sfConfig::get('sf_charset', 'UTF-8'));

	if (false === ($pos = strpos($html, '</head>'))) {
		$html = '<head><meta http-equiv="Content-Type" content="'.$this->response->getContentType().'"/></head>' . $html;
	}

    @$dom->loadHTML($html);
    $dom = $this->fillInDom($dom, $formName, $formId, $values);
	$html = $dom->saveHTML();

    if ($pos === false) {
    	// Remove Header
		$end   = strpos($html, '<body>');
		$html = substr_replace($html, '', 0, $end + 6);

		$end   = strpos($html, '</body>');
		$html = substr_replace($html, '', $end, strlen($html)-$end);
    }
    return $html;
  }

Change History

05/02/08 10:03:24 changed by FabianLange

  • owner changed from fabien to FabianLange.
  • status changed from new to assigned.

confirmed

05/02/08 10:28:39 changed by FabianLange

  • milestone set to 1.0.14.

your quickhack is not far from what has to be done. loadHTML requires the meta content-type. I aded it same way, but I used the dom tree for removign the head later on again :-)

05/02/08 10:31:47 changed by FabianLange

  • status changed from assigned to closed.
  • resolution set to fixed.

(in r8716) patched sfFillInForm so that in html mode it adds a content-type meta if non present so that dom->loadHTML works correctly. (closes #2653)

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.