Development

Changeset 1752

You must first sign up to be able to contribute.

Changeset 1752

Show
Ignore:
Timestamp:
08/23/06 09:08:02 (3 years ago)
Author:
fabien
Message:
  • added a new charset parameter in settings.yml (defaults to utf-8)
  • changed default content-type from text/html; charset=utf-8 to text/html in view.yml skeleton
  • changed all occurences of UTF-8 in symfony core by sfConfig::get('sf_charset') (escpecially all htmlentities() calls)
  • use the new charset for the sfFillFormFilter filter (and iconv to convert back to utf-8 - needed by DOMElement::setAttribute())
  • automatically add the charset to the content-type when sending headers to the browser

I hope this will fix all our problems with non utf-8 charset support in symfony and it does not break BC.
If you have a non UTF-8 symfony website, please test it and give us some feedback.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/data/config/settings.yml

    r1641 r1752  
    7171 
    7272    autoloading_functions: ~ 
     73 
     74    charset: utf-8 
  • trunk/data/skeleton/app/app/config/view.yml

    r1631 r1752  
    11default: 
    22  http_metas: 
    3     content-type: text/html; charset=utf-8 
     3    content-type: text/html 
    44 
    55  metas: 
  • trunk/lib/config/sfViewConfigHandler.class.php

    r1644 r1752  
    176176    foreach ($this->mergeConfigValue('metas', $viewName) as $name => $content) 
    177177    { 
    178       $data[] = sprintf("    \$response->addMeta('%s', '%s', false, true);", $name, str_replace('\'', '\\\'', preg_replace('/&(?=\w+;)/', '&', htmlentities($content, ENT_QUOTES, 'UTF-8')))); 
     178      $data[] = sprintf("    \$response->addMeta('%s', '%s', false, true);", $name, str_replace('\'', '\\\'', preg_replace('/&(?=\w+;)/', '&', htmlentities($content, ENT_QUOTES, sfConfig::get('sf_charset'))))); 
    179179    } 
    180180 
  • trunk/lib/debug/sfWebDebug.class.php

    r1641 r1752  
    131131 
    132132    // escape HTML 
    133     $log_line = htmlentities($log_line, ENT_QUOTES, 'UTF-8'); 
     133    $log_line = htmlentities($log_line, ENT_QUOTES, sfConfig::get('sf_charset')); 
    134134 
    135135    // replace constants value with constant name 
     
    373373    $content = ' 
    374374    <h2>'.$id.' <a href="#" onclick="sfWebDebugToggle(\'sfWebDebug'.$id.'\'); return false;"><img src="'.$this->base_image_path.'/toggle.gif" alt="" /></a></h2> 
    375     <div id="sfWebDebug'.$id.'" style="display: none"><pre>'.htmlentities(@sfYaml::Dump($values), ENT_QUOTES, 'UTF-8').'</pre></div> 
     375    <div id="sfWebDebug'.$id.'" style="display: none"><pre>'.htmlentities(@sfYaml::Dump($values), ENT_QUOTES, sfConfig::get('sf_charset')).'</pre></div> 
    376376    '; 
    377377 
  • trunk/lib/filter/sfFillInFormFilter.class.php

    r1415 r1752  
    2626    $request  = $context->getRequest(); 
    2727 
    28     $doc = new DomDocument('1.0', 'UTF-8'); 
     28    $doc = new DomDocument('1.0', sfConfig::get('sf_charset')); 
    2929    @$doc->loadHTML($response->getContent()); 
    3030    $xpath = new DomXPath($doc); 
     
    8686            if ($request->hasParameter($element->getAttribute('name'))) 
    8787            { 
    88               $element->setAttribute('value', $this->espaceRequestParameter($request, $element->getAttribute('name'))); 
     88              $element->setAttribute('value', $this->escapeRequestParameter($request, $element->getAttribute('name'))); 
    8989            } 
    9090          } 
     
    9696            $element->removeChild($child_node); 
    9797          } 
    98           $element->appendChild($doc->createTextNode($this->espaceRequestParameter($request, $element->getAttribute('name')))); 
     98          $element->appendChild($doc->createTextNode($this->escapeRequestParameter($request, $element->getAttribute('name')))); 
    9999        } 
    100100        else if ($element->nodeName == 'select') 
     
    131131  } 
    132132 
    133   private function espaceRequestParameter($request, $name) 
     133  private function escapeRequestParameter($request, $name) 
    134134  { 
    135135    $value = $request->getParameter($name); 
     136 
     137    if (extension_loaded('iconv') && strtolower(sfConfig::get('sf_charset')) != 'utf-8') 
     138    { 
     139      $new_value = iconv(sfConfig::get('sf_charset'), 'UTF-8', $value); 
     140      if (false !== $new_value) 
     141      { 
     142        $value = $new_value; 
     143      } 
     144    } 
     145 
    136146    if (isset($this->escapers[$name])) 
    137147    { 
  • trunk/lib/helper/EscapingHelper.php

    r1429 r1752  
    4242  // Numbers and boolean values get turned into strings which can cause problems 
    4343  // with type comparisons (e.g. === or is_int() etc). 
    44   return is_string($value) ? htmlentities($value, ENT_QUOTES, 'UTF-8') : $value; 
     44  return is_string($value) ? htmlentities($value, ENT_QUOTES, sfConfig::get('sf_charset')) : $value; 
    4545} 
    4646 
  • trunk/lib/response/sfWebResponse.class.php

    r1734 r1752  
    244244    } 
    245245 
     246    $this->fixHeaders(); 
     247 
    246248    // headers 
    247249    foreach ($this->headers as $name => $values) 
     
    277279  } 
    278280 
     281  private function fixHeaders() 
     282  { 
     283    // add charset to the content-type header if needed 
     284    if (false === stripos($this->getContentType(), 'charset')) 
     285    { 
     286      $this->setContentType($this->getContentType().'; charset='.sfConfig::get('sf_charset')); 
     287    } 
     288  } 
     289 
    279290  private function normalizeHeaderName($name) 
    280291  { 
     
    377388      if (!$doNotEscape) 
    378389      { 
    379         $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); 
     390        $value = htmlentities($value, ENT_QUOTES, sfConfig::get('sf_charset')); 
    380391      } 
    381392 
     
    400411      } 
    401412 
    402       $title = htmlentities($title, ENT_QUOTES, 'UTF-8'); 
     413      $title = htmlentities($title, ENT_QUOTES, sfConfig::get('sf_charset')); 
    403414    } 
    404415 

The Sensio Labs Network

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