Author: FabianLange
Date: 2010-02-02 14:09:54 +0100 (Tue, 02 Feb 2010)
New Revision: 27415
Modified:
branches/1.2/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
branches/1.2/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
branches/1.3/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
branches/1.3/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
Log:
[1.2, 1.3] fixed sfFillInForm so that it doesn't loose encoding information
(fixes #3943)
Modified:
branches/1.2/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
===================================================================
--- branches/1.2/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
2010-02-02 12:27:07 UTC (rev 27414)
+++ branches/1.2/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
2010-02-02 13:09:54 UTC (rev 27415)
@@ -77,7 +77,7 @@
public function fillInXhtml($xml, $formName, $formId, $values)
{
$xhtml = $this->fillInXml($xml, $formName, $formId, $values);
- $prolog_regexp = '/^' . preg_quote('<?xml version="1.0"?>') . '\s*/';
+ $prolog_regexp = '/^' . preg_quote('<?xml version="1.0"
encoding="'.sfConfig::get('sf_charset', 'UTF-8').'"?>') . '\s*/';
return preg_replace($prolog_regexp, '', $xhtml);
}
@@ -89,14 +89,21 @@
public function fillInXml($xml, $formName, $formId, $values)
{
$dom = new DomDocument('1.0', sfConfig::get('sf_charset', 'UTF-8'));
+
+ // pages not having a doctype need it for loading
if (strpos($xml,'<!DOCTYPE') === false)
{
$xml = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '.
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.
$xml;
}
+
@$dom->loadXML($xml);
-
+ // loadXML will unset encoding if it was not defined in the source, no
matter what the DomDocument constructor said
+ if($dom->encoding === null)
+ {
+ $dom->encoding = sfConfig::get('sf_charset', 'UTF-8');
+ }
$dom = $this->fillInDom($dom, $formName, $formId, $values);
return $dom->saveXML();
Modified:
branches/1.2/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
===================================================================
---
branches/1.2/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
2010-02-02 12:27:07 UTC (rev 27414)
+++
branches/1.2/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
2010-02-02 13:09:54 UTC (rev 27415)
@@ -11,7 +11,7 @@
require_once(dirname(__FILE__).'/../../../../../../test/bootstrap/unit.php');
require_once(dirname(__FILE__).'/../../../lib/util/sfFillInForm.class.php');
-$t = new lime_test(74, new lime_output_color());
+$t = new lime_test(74);
$html = <<<EOF
<html>
@@ -276,7 +276,7 @@
$xml = $f->fillInXml($xml, 'form', null, array('foo' => 'bar'));
$t->like($xml, '#<input type="text" name="foo" value="bar"\s*/>#',
'->fillInXml() outputs valid XML');
$t->like($xml, '#<option value="selected" selected="selected">#',
'->fillInXml() outputs valid XML');
-$t->like($xml, '#<\?xml version="1.0"\?>#', '->fillInXml() outputs XML
prolog');
+$t->like($xml, '#<\?xml version="1.0" encoding="UTF-8"\?>#', '->fillInXml()
outputs XML prolog');
// ->fillInXhtml()
$xml = $f->fillInXhtml($xml, 'form', null, array('foo' => 'bar'));
Modified:
branches/1.3/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
===================================================================
--- branches/1.3/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
2010-02-02 12:27:07 UTC (rev 27414)
+++ branches/1.3/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
2010-02-02 13:09:54 UTC (rev 27415)
@@ -77,7 +77,7 @@
public function fillInXhtml($xml, $formName, $formId, $values)
{
$xhtml = $this->fillInXml($xml, $formName, $formId, $values);
- $prolog_regexp = '/^' . preg_quote('<?xml version="1.0"?>') . '\s*/';
+ $prolog_regexp = '/^' . preg_quote('<?xml version="1.0"
encoding="'.sfConfig::get('sf_charset', 'UTF-8').'"?>') . '\s*/';
return preg_replace($prolog_regexp, '', $xhtml);
}
@@ -89,14 +89,21 @@
public function fillInXml($xml, $formName, $formId, $values)
{
$dom = new DomDocument('1.0', sfConfig::get('sf_charset', 'UTF-8'));
+
+ // pages not having a doctype need it for loading
if (strpos($xml,'<!DOCTYPE') === false)
{
$xml = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '.
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.
$xml;
}
+
@$dom->loadXML($xml);
-
+ // loadXML will unset encoding if it was not defined in the source, no
matter what the DomDocument constructor said
+ if($dom->encoding === null)
+ {
+ $dom->encoding = sfConfig::get('sf_charset', 'UTF-8');
+ }
$dom = $this->fillInDom($dom, $formName, $formId, $values);
return $dom->saveXML();
Modified:
branches/1.3/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
===================================================================
---
branches/1.3/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
2010-02-02 12:27:07 UTC (rev 27414)
+++
branches/1.3/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
2010-02-02 13:09:54 UTC (rev 27415)
@@ -276,7 +276,7 @@
$xml = $f->fillInXml($xml, 'form', null, array('foo' => 'bar'));
$t->like($xml, '#<input type="text" name="foo" value="bar"\s*/>#',
'->fillInXml() outputs valid XML');
$t->like($xml, '#<option value="selected" selected="selected">#',
'->fillInXml() outputs valid XML');
-$t->like($xml, '#<\?xml version="1.0"\?>#', '->fillInXml() outputs XML
prolog');
+$t->like($xml, '#<\?xml version="1.0" encoding="UTF-8"\?>#', '->fillInXml()
outputs XML prolog');
// ->fillInXhtml()
$xml = $f->fillInXhtml($xml, 'form', null, array('foo' => 'bar'));
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.